Re: [PATCH] pinctrl: nuvoton: fix fwnode_handle leaks in npcm7xx_gpio_of() and npcm8xx_gpio_fw()

From: Linus Walleij

Date: Wed Nov 04 2026 - 08:40:00 EST


On Sun, Oct 25, 2026 at 7:43 PM Selby Mashiki <mashikiselby@xxxxxxxxx> wrote:

> Both npcm7xx_gpio_of() and npcm8xx_gpio_fw() iterate over GPIO bank
> child nodes using for_each_gpiochip_node(dev, child), which holds a
> reference on child during each iteration. Returning early on any of the
> error paths inside the loop leaks the child fwnode_handle reference.
>
> Additionally, both functions call fwnode_property_get_reference_args()
> to parse the "gpio-ranges" property into args, which acquires a
> reference on args.fwnode that is never released.
>
> Use the __free(fwnode_handle) cleanup attribute for child so early
> returns automatically drop the reference, and call
> fwnode_handle_put(args.fwnode) after fwnode_property_get_reference_args()
> succeeds.
>
> Fixes: 3b588e43ee5c ("pinctrl: nuvoton: add NPCM7xx pinctrl and GPIO driver")
> Fixes: acf4884a5717 ("pinctrl: nuvoton: add NPCM8XX pinctrl and GPIO driver")
> Signed-off-by: Selby Mashiki <mashikiselby@xxxxxxxxx>

Patch applied as nonurgent fix.

Yours,
Linus Walleij