Hi Geert, Thanks for your feedback! > From: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> > Sent: 11 February 2025 15:12 > Subject: Re: [PATCH v4] irqchip/renesas-rzg2l: Fix missing put_device > > Hi Fabrizio, > > On Fri, 11 Oct 2024 at 19:20, Fabrizio Castro > <fabrizio.castro.jz@xxxxxxxxxxx> wrote: > > rzg2l_irqc_common_init calls of_find_device_by_node, but the > > corresponding put_device call is missing. > > This also gets reported by make coccicheck. > > > > Make use of the cleanup interfaces from cleanup.h to call into > > __free_put_device (which in turn calls into put_device) when > > leaving function rzg2l_irqc_common_init and variable "dev" goes > > out of scope. > > > > Mind that we don't want to "put" "dev" when rzg2l_irqc_common_init > > completes successfully, therefore assign NULL to "dev" to prevent > > __free_put_device from calling into put_device within the successful > > path. > > > > "make coccicheck" will still complain about missing put_device calls, > > but those are false positives now. > > > > Fixes: 3fed09559cd8 ("irqchip: Add RZ/G2L IA55 Interrupt Controller driver") > > Signed-off-by: Fabrizio Castro <fabrizio.castro.jz@xxxxxxxxxxx> > > Revisiting commit d038109ac1c6bf61 ("irqchip/renesas-rzg2l: Fix missing > put_device")... > > > --- a/drivers/irqchip/irq-renesas-rzg2l.c > > +++ b/drivers/irqchip/irq-renesas-rzg2l.c > > @@ -8,6 +8,7 @@ > > */ > > > > #include <linux/bitfield.h> > > +#include <linux/cleanup.h> > > #include <linux/clk.h> > > #include <linux/err.h> > > #include <linux/io.h> > > @@ -530,12 +531,12 @@ static int rzg2l_irqc_parse_interrupts(struct rzg2l_irqc_priv *priv, > > static int rzg2l_irqc_common_init(struct device_node *node, struct device_node *parent, > > const struct irq_chip *irq_chip) > > { > > + struct platform_device *pdev = of_find_device_by_node(node); > > + struct device *dev __free(put_device) = pdev ? &pdev->dev : NULL; > > Now there is a variable holding "&pdev->dev", all below references > to the latter can be replaced by "dev"... Right! I will shortly send a patch for this. > > > struct irq_domain *irq_domain, *parent_domain; > > - struct platform_device *pdev; > > struct reset_control *resetn; > > int ret; > > > > - pdev = of_find_device_by_node(node); > > if (!pdev) > > return -ENODEV; > > > > @@ -591,6 +592,17 @@ static int rzg2l_irqc_common_init(struct device_node *node, struct device_node > * > > > > register_syscore_ops(&rzg2l_irqc_syscore_ops); > > > > + /* > > + * Prevent the cleanup function from invoking put_device by assigning > > + * NULL to dev. > > + * > > + * make coccicheck will complain about missing put_device calls, but > > + * those are false positives, as dev will be automatically "put" via > > + * __free_put_device on the failing path. > > + * On the successful path we don't actually want to "put" dev. > > + */ > > + dev = NULL; > > + > > return 0; > > Can't the above be replaced by > > no_free_ptr(dev); > > ? Or would Coccinelle still complain? If I use no_free_ptr the compiler complains that its return value is not used: In file included from ../drivers/irqchip/irq-renesas-rzg2l.c:11: ../drivers/irqchip/irq-renesas-rzg2l.c: In function ‘rzg2l_irqc_common_init’: ../include/linux/cleanup.h:215:15: warning: ignoring return value of ‘__must_check_fn’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 215 | ((typeof(p)) __must_check_fn(__get_and_null(p, NULL))) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../drivers/irqchip/irq-renesas-rzg2l.c:595:2: note: in expansion of macro ‘no_free_ptr’ 595 | no_free_ptr(dev); | ^~~~~~~~~~~ Cheers, Fab > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds