diff mbox series

[v3,5/5] pinctrl: at91: Utilise temporary variable for struct device

Message ID 20230215134242.37618-6-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v3,1/5] pinctrl: at91: use devm_kasprintf() to avoid potential leaks (part 2) | expand

Commit Message

Andy Shevchenko Feb. 15, 2023, 1:42 p.m. UTC
We have a temporary variable to keep pointer to struct device.
Utilise it inside the ->probe() implementation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/pinctrl-at91.c | 60 +++++++++++++++-------------------
 1 file changed, 26 insertions(+), 34 deletions(-)

Comments

Claudiu Beznea Feb. 17, 2023, 11:54 a.m. UTC | #1
On 15.02.2023 15:42, Andy Shevchenko wrote:
> @@ -1758,7 +1750,7 @@ static int at91_gpio_of_irq_setup(struct platform_device *pdev,
>         if (!gpiochip_prev) {
>                 girq->parent_handler = gpio_irq_handler;
>                 girq->num_parents = 1;
> -               girq->parents = devm_kcalloc(&pdev->dev, 1,
> +               girq->parents = devm_kcalloc(dev, girq->num_parents,

There is still the change of the 2nd argument of devm_kcalloc() from 1 ->
girq->num_parents (no functional change, though) which doesn't match the
purpose of the patch and is not specified anywhere. Other than this:

Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>

>                                              sizeof(*girq->parents),
>                                              GFP_KERNEL);
Andy Shevchenko Feb. 17, 2023, 11:59 a.m. UTC | #2
On Fri, Feb 17, 2023 at 11:54:02AM +0000, Claudiu.Beznea@microchip.com wrote:
> On 15.02.2023 15:42, Andy Shevchenko wrote:
> > @@ -1758,7 +1750,7 @@ static int at91_gpio_of_irq_setup(struct platform_device *pdev,
> >         if (!gpiochip_prev) {
> >                 girq->parent_handler = gpio_irq_handler;
> >                 girq->num_parents = 1;
> > -               girq->parents = devm_kcalloc(&pdev->dev, 1,
> > +               girq->parents = devm_kcalloc(dev, girq->num_parents,
> 
> There is still the change of the 2nd argument of devm_kcalloc() from 1 ->
> girq->num_parents (no functional change, though) which doesn't match the
> purpose of the patch and is not specified anywhere. Other than this:
> 
> Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> 
> >                                              sizeof(*girq->parents),
> >                                              GFP_KERNEL);

Thanks for review. I have no time to fix this. So if Linus is okay to take
the first 4 patches, I'm fine. You or somebody else can submit an updated
5th patch later on.
Linus Walleij Feb. 27, 2023, 9:44 p.m. UTC | #3
On Fri, Feb 17, 2023 at 12:59 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Fri, Feb 17, 2023 at 11:54:02AM +0000, Claudiu.Beznea@microchip.com wrote:
> > On 15.02.2023 15:42, Andy Shevchenko wrote:
> > > @@ -1758,7 +1750,7 @@ static int at91_gpio_of_irq_setup(struct platform_device *pdev,
> > >         if (!gpiochip_prev) {
> > >                 girq->parent_handler = gpio_irq_handler;
> > >                 girq->num_parents = 1;
> > > -               girq->parents = devm_kcalloc(&pdev->dev, 1,
> > > +               girq->parents = devm_kcalloc(dev, girq->num_parents,
> >
> > There is still the change of the 2nd argument of devm_kcalloc() from 1 ->
> > girq->num_parents (no functional change, though) which doesn't match the
> > purpose of the patch and is not specified anywhere. Other than this:
> >
> > Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> >
> > >                                              sizeof(*girq->parents),
> > >                                              GFP_KERNEL);
>
> Thanks for review. I have no time to fix this. So if Linus is okay to take
> the first 4 patches, I'm fine. You or somebody else can submit an updated
> 5th patch later on.

I applied all 5 patches. The num_parents is set to 1 on the line right
above and it's the right thing to do, and has a reviewed tag so I don't
see the problem with this patch, let's not overinvest in process.

Thanks for the very nice cleanups!

I applied it locally so it won't be in linux-next until after the merge
window closes.

Yours,
Linus Walleij
Andy Shevchenko Feb. 27, 2023, 10:20 p.m. UTC | #4
On Mon, Feb 27, 2023 at 10:44:21PM +0100, Linus Walleij wrote:
> On Fri, Feb 17, 2023 at 12:59 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Fri, Feb 17, 2023 at 11:54:02AM +0000, Claudiu.Beznea@microchip.com wrote:
> > > On 15.02.2023 15:42, Andy Shevchenko wrote:

...

> > > >                 girq->num_parents = 1;
> > > > -               girq->parents = devm_kcalloc(&pdev->dev, 1,
> > > > +               girq->parents = devm_kcalloc(dev, girq->num_parents,
> > >
> > > There is still the change of the 2nd argument of devm_kcalloc() from 1 ->
> > > girq->num_parents (no functional change, though) which doesn't match the
> > > purpose of the patch and is not specified anywhere. Other than this:
> > >
> > > Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> > >
> > > >                                              sizeof(*girq->parents),
> > > >                                              GFP_KERNEL);
> >
n
> > Thanks for review. I have no time to fix this. So if Linus is okay to take
> > the first 4 patches, I'm fine. You or somebody else can submit an updated
> > 5th patch later on.
> 
> I applied all 5 patches. The num_parents is set to 1 on the line right
> above and it's the right thing to do, and has a reviewed tag so I don't
> see the problem with this patch, let's not overinvest in process.
> 
> Thanks for the very nice cleanups!

Thank you!

> I applied it locally so it won't be in linux-next until after the merge
> window closes.
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 08f88403affb..de48a8e0f85f 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -1304,7 +1304,7 @@  static int at91_pinctrl_probe_dt(struct platform_device *pdev,
 	if (!np)
 		return -ENODEV;
 
-	info->dev = &pdev->dev;
+	info->dev = dev;
 	info->ops = of_device_get_match_data(dev);
 	at91_pinctrl_child_count(info, np);
 
@@ -1324,35 +1324,31 @@  static int at91_pinctrl_probe_dt(struct platform_device *pdev,
 	if (ret)
 		return ret;
 
-	dev_dbg(&pdev->dev, "nmux = %d\n", info->nmux);
+	dev_dbg(dev, "nmux = %d\n", info->nmux);
 
-	dev_dbg(&pdev->dev, "mux-mask\n");
+	dev_dbg(dev, "mux-mask\n");
 	tmp = info->mux_mask;
 	for (i = 0; i < gpio_banks; i++) {
 		for (j = 0; j < info->nmux; j++, tmp++) {
-			dev_dbg(&pdev->dev, "%d:%d\t0x%x\n", i, j, tmp[0]);
+			dev_dbg(dev, "%d:%d\t0x%x\n", i, j, tmp[0]);
 		}
 	}
 
-	dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
-	dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
-	info->functions = devm_kcalloc(&pdev->dev,
-					info->nfunctions,
-					sizeof(struct at91_pmx_func),
-					GFP_KERNEL);
+	dev_dbg(dev, "nfunctions = %d\n", info->nfunctions);
+	dev_dbg(dev, "ngroups = %d\n", info->ngroups);
+	info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions),
+				       GFP_KERNEL);
 	if (!info->functions)
 		return -ENOMEM;
 
-	info->groups = devm_kcalloc(&pdev->dev,
-					info->ngroups,
-					sizeof(struct at91_pin_group),
-					GFP_KERNEL);
+	info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups),
+				    GFP_KERNEL);
 	if (!info->groups)
 		return -ENOMEM;
 
-	dev_dbg(&pdev->dev, "nbanks = %d\n", gpio_banks);
-	dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
-	dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
+	dev_dbg(dev, "nbanks = %d\n", gpio_banks);
+	dev_dbg(dev, "nfunctions = %d\n", info->nfunctions);
+	dev_dbg(dev, "ngroups = %d\n", info->ngroups);
 
 	i = 0;
 
@@ -1376,7 +1372,7 @@  static int at91_pinctrl_probe(struct platform_device *pdev)
 	struct pinctrl_pin_desc *pdesc;
 	int ret, i, j, k;
 
-	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+	info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
 
@@ -1384,13 +1380,10 @@  static int at91_pinctrl_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	at91_pinctrl_desc.name = dev_name(&pdev->dev);
+	at91_pinctrl_desc.name = dev_name(dev);
 	at91_pinctrl_desc.npins = gpio_banks * MAX_NB_GPIO_PER_BANK;
 	at91_pinctrl_desc.pins = pdesc =
-		devm_kcalloc(&pdev->dev,
-			     at91_pinctrl_desc.npins, sizeof(*pdesc),
-			     GFP_KERNEL);
-
+		devm_kcalloc(dev, at91_pinctrl_desc.npins, sizeof(*pdesc), GFP_KERNEL);
 	if (!at91_pinctrl_desc.pins)
 		return -ENOMEM;
 
@@ -1413,8 +1406,7 @@  static int at91_pinctrl_probe(struct platform_device *pdev)
 	}
 
 	platform_set_drvdata(pdev, info);
-	info->pctl = devm_pinctrl_register(&pdev->dev, &at91_pinctrl_desc,
-					   info);
+	info->pctl = devm_pinctrl_register(dev, &at91_pinctrl_desc, info);
 	if (IS_ERR(info->pctl))
 		return dev_err_probe(dev, PTR_ERR(info->pctl), "could not register AT91 pinctrl driver\n");
 
@@ -1423,7 +1415,7 @@  static int at91_pinctrl_probe(struct platform_device *pdev)
 		if (gpio_chips[i])
 			pinctrl_add_gpio_range(info->pctl, &gpio_chips[i]->range);
 
-	dev_info(&pdev->dev, "initialized AT91 pinctrl driver\n");
+	dev_info(dev, "initialized AT91 pinctrl driver\n");
 
 	return 0;
 }
@@ -1714,6 +1706,7 @@  static void gpio_irq_handler(struct irq_desc *desc)
 static int at91_gpio_of_irq_setup(struct platform_device *pdev,
 				  struct at91_gpio_chip *at91_gpio)
 {
+	struct device		*dev = &pdev->dev;
 	struct gpio_chip	*gpiochip_prev = NULL;
 	struct at91_gpio_chip   *prev = NULL;
 	struct irq_data		*d = irq_get_irq_data(at91_gpio->pioc_virq);
@@ -1721,8 +1714,7 @@  static int at91_gpio_of_irq_setup(struct platform_device *pdev,
 	struct gpio_irq_chip	*girq;
 	int i;
 
-	gpio_irqchip = devm_kzalloc(&pdev->dev, sizeof(*gpio_irqchip),
-				    GFP_KERNEL);
+	gpio_irqchip = devm_kzalloc(dev, sizeof(*gpio_irqchip), GFP_KERNEL);
 	if (!gpio_irqchip)
 		return -ENOMEM;
 
@@ -1758,7 +1750,7 @@  static int at91_gpio_of_irq_setup(struct platform_device *pdev,
 	if (!gpiochip_prev) {
 		girq->parent_handler = gpio_irq_handler;
 		girq->num_parents = 1;
-		girq->parents = devm_kcalloc(&pdev->dev, 1,
+		girq->parents = devm_kcalloc(dev, girq->num_parents,
 					     sizeof(*girq->parents),
 					     GFP_KERNEL);
 		if (!girq->parents)
@@ -1824,7 +1816,7 @@  static int at91_gpio_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	at91_chip = devm_kzalloc(&pdev->dev, sizeof(*at91_chip), GFP_KERNEL);
+	at91_chip = devm_kzalloc(dev, sizeof(*at91_chip), GFP_KERNEL);
 	if (!at91_chip)
 		return -ENOMEM;
 
@@ -1836,7 +1828,7 @@  static int at91_gpio_probe(struct platform_device *pdev)
 	at91_chip->pioc_virq = irq;
 	at91_chip->pioc_idx = alias_idx;
 
-	at91_chip->clock = devm_clk_get_enabled(&pdev->dev, NULL);
+	at91_chip->clock = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(at91_chip->clock))
 		return dev_err_probe(dev, PTR_ERR(at91_chip->clock), "failed to get clock, ignoring.\n");
 
@@ -1844,8 +1836,8 @@  static int at91_gpio_probe(struct platform_device *pdev)
 	at91_chip->id = alias_idx;
 
 	chip = &at91_chip->chip;
-	chip->label = dev_name(&pdev->dev);
-	chip->parent = &pdev->dev;
+	chip->label = dev_name(dev);
+	chip->parent = dev;
 	chip->owner = THIS_MODULE;
 	chip->base = alias_idx * MAX_NB_GPIO_PER_BANK;
 
@@ -1886,7 +1878,7 @@  static int at91_gpio_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, at91_chip);
 	gpio_banks = max(gpio_banks, alias_idx + 1);
 
-	dev_info(&pdev->dev, "at address %p\n", at91_chip->regbase);
+	dev_info(dev, "at address %p\n", at91_chip->regbase);
 
 	return 0;
 }