[PATCH] gpio: dwapb_gpio: Using wrong function to free memory
Quentin Schulz
quentin.schulz at cherry.de
Fri Jul 25 14:06:52 CEST 2025
Hi Andrew,
On 7/25/25 1:48 PM, Andrew Goodbody wrote:
> In gpio_dwapb_bind plat is used to reference memory allocated by
> devm_kcalloc but it is attempted to be freed using kfree. Instead free
> this memory using the correct devm_kfree function.
>
> This issue was found by Smatch.
>
> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
> ---
> drivers/gpio/dwapb_gpio.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c
> index 04639a4cb68..7ab48780332 100644
> --- a/drivers/gpio/dwapb_gpio.c
> +++ b/drivers/gpio/dwapb_gpio.c
> @@ -193,7 +193,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
> ofnode_get_name(node));
> plat->name = strdup(name);
> if (!plat->name) {
> - kfree(plat);
> + devm_kfree(dev, plat);
Why do we even need a free in the first place, isn't that the role of
devm_<wahetever> to undo things properly in case of failed probe (or
removal of the driver)?
According to
https://lore.kernel.org/u-boot/20250722-usb_onboard_hub_cypress_hx3-v4-2-91c3ee958c0e@thaumatec.com/,
you need DEVRES to be enabled for that to happen.
So I'm really wondering what's the purpose of having devm_ functions if
we need to undo them by hand if DEVRES isn't enabled. This is very
confusing and misleading and will lead to mistakes (I for sure will
never remember to undo devm functions in drivers I write or modify).
This patch looks good anyway, so
Acked-by: Quentin Schulz <quentin.schulz at cherry.de>
Thanks!
Quentin
More information about the U-Boot
mailing list