[PATCH] pinctrl: stm32: Fix fwnode reference leak in stm32_gpiolib_register_bank()

Andy Shevchenko andriy.shevchenko at linux.intel.com
Tue Oct 13 06:16:42 PDT 2026


On Sun, Oct 11, 2026 at 02:17:22PM +0800, Ma Ke wrote:
> stm32_gpiolib_register_bank() walks the "gpio-ranges" property with
> fwnode_property_get_reference_args().  As documented in
> drivers/base/property.c:
> 
>  * The caller is responsible for calling fwnode_handle_put() on the
>  * returned @args->fwnode pointer.
> 
> The returned reference is never put.  The function calls the helper
> twice, once directly and then repeatedly in a while loop, and each
> call overwrites args, so only the last reference is even reachable
> and all the earlier ones are leaked for good.
> 
> Put the reference as soon as args.args[] has been consumed, both for
> the initial call and for every iteration of the loop.
> 
> Found by code review.

...

>  		/* get the last defined gpio line (offset + nb of pins) */
>  		npins = args.args[0] + args.args[2];
> -		while (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, ++i, &args))
> +		fwnode_handle_put(args.fwnode);
> +
> +		while (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, ++i, &args)) {
>  			npins = max(npins, (int)(args.args[0] + args.args[2]));
> +			fwnode_handle_put(args.fwnode);
> +		}

Can we use GPIOLIB facility to fulfil the task? Yeah, it seems non-trivial
change, so for the quick fix the above seems okay.

-- 
With Best Regards,
Andy Shevchenko





More information about the linux-arm-kernel mailing list