[U-Boot] [PATCH] gpio: dwapb_gpio: Change to use devm_kcalloc()

Marek Vasut marex at denx.de
Thu Sep 6 10:05:27 UTC 2018


On 09/06/2018 04:48 PM, Ley Foon Tan wrote:
> Change to use managed resource function devm_kcalloc(),
> so it will auto free memory when driver is removed.
> 
> Signed-off-by: Ley Foon Tan <ley.foon.tan at intel.com>
> ---
>  drivers/gpio/dwapb_gpio.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c
> index 0f6574d..1594434 100644
> --- a/drivers/gpio/dwapb_gpio.c
> +++ b/drivers/gpio/dwapb_gpio.c
> @@ -171,8 +171,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
>  		if (!fdtdec_get_bool(blob, node, "gpio-controller"))
>  			continue;
>  
> -		plat = NULL;
> -		plat = calloc(1, sizeof(*plat));
> +		plat = devm_kcalloc(dev, 1, sizeof(*plat), GFP_KERNEL);
>  		if (!plat)
>  			return -ENOMEM;

You also need to drop the matching free()

-- 
Best regards,
Marek Vasut


More information about the U-Boot mailing list