* [U-Boot] [PATCH v3] gpio: dwapb_gpio: Change to use devm_kcalloc()
@ 2018-09-19 8:26 Ley Foon Tan
2018-09-19 8:53 ` Marek Vasut
0 siblings, 1 reply; 2+ messages in thread
From: Ley Foon Tan @ 2018-09-19 8:26 UTC (permalink / raw)
To: u-boot
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@intel.com>
---
v3:
- Remove goto and return directly.
v2:
- Remove free() function.
---
drivers/gpio/dwapb_gpio.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c
index 0f6574d..68836a7 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;
@@ -181,23 +180,17 @@ static int gpio_dwapb_bind(struct udevice *dev)
plat->pins = fdtdec_get_int(blob, node, "snps,nr-gpios", 0);
plat->name = fdt_stringlist_get(blob, node, "bank-name", 0,
NULL);
- if (ret)
- goto err;
ret = device_bind(dev, dev->driver, plat->name,
plat, -1, &subdev);
if (ret)
- goto err;
+ return ret;
dev_set_of_offset(subdev, node);
bank++;
}
return 0;
-
-err:
- free(plat);
- return ret;
}
static int gpio_dwapb_remove(struct udevice *dev)
--
2.2.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [PATCH v3] gpio: dwapb_gpio: Change to use devm_kcalloc()
2018-09-19 8:26 [U-Boot] [PATCH v3] gpio: dwapb_gpio: Change to use devm_kcalloc() Ley Foon Tan
@ 2018-09-19 8:53 ` Marek Vasut
0 siblings, 0 replies; 2+ messages in thread
From: Marek Vasut @ 2018-09-19 8:53 UTC (permalink / raw)
To: u-boot
On 09/19/2018 10:26 AM, 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@intel.com>
>
> ---
> v3:
> - Remove goto and return directly.
>
> v2:
> - Remove free() function.
> ---
> drivers/gpio/dwapb_gpio.c | 11 ++---------
> 1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c
> index 0f6574d..68836a7 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;
>
> @@ -181,23 +180,17 @@ static int gpio_dwapb_bind(struct udevice *dev)
> plat->pins = fdtdec_get_int(blob, node, "snps,nr-gpios", 0);
> plat->name = fdt_stringlist_get(blob, node, "bank-name", 0,
> NULL);
> - if (ret)
> - goto err;
>
> ret = device_bind(dev, dev->driver, plat->name,
> plat, -1, &subdev);
btw. on DW GPIO with multiple banks, if this bind fails for any bank but
the first, the driver won't clean up properly ;-)
> if (ret)
> - goto err;
> + return ret;
>
> dev_set_of_offset(subdev, node);
> bank++;
> }
>
> return 0;
> -
> -err:
> - free(plat);
> - return ret;
> }
>
> static int gpio_dwapb_remove(struct udevice *dev)
>
Applied, thanks
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-09-19 8:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-19 8:26 [U-Boot] [PATCH v3] gpio: dwapb_gpio: Change to use devm_kcalloc() Ley Foon Tan
2018-09-19 8:53 ` Marek Vasut
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.