Skip to contentSkip to conversation

gpio: dwapb_gpio: Change to use devm_kcalloc()

PATCH Superseded Ley Foon Tan 3 participants 3 messages Sep 6, 2018 – Sep 7, 2018 GPIO

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: dwapb_gpio: Change to use devm_kcalloc()

Change to use managed resource function devm_kcalloc(), so it will auto free memory when driver is removed.

---
 drivers/gpio/dwapb_gpio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/dwapb_gpio.c +1 -2
index 0f6574d..1594434 100644
@@ -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;
 
Signature · 1 line
2.2.2
#1 lore raw

PATCH 1/1 gpio: dwapb_gpio: Change to use devm_kcalloc()

Quoted 13 lines · Ley Foon Tan

Change to use managed resource function devm_kcalloc(), so it will auto free memory when driver is removed.

---
 drivers/gpio/dwapb_gpio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/dwapb_gpio.c +0 -0
index 0f6574d..1594434 100644

drivers/gpio/dwapb_gpio.c static int gpio_dwapb_bind(struct udevice *dev) · line 176

Quoted 8 lines
drivers/gpio/dwapb_gpio.c +1 -2
@@ -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()

Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH 1/1 gpio: dwapb_gpio: Change to use devm_kcalloc()

Quoted 18 lines · Marek Vasut
Quoted 16 lines · Ley Foon Tan

Change to use managed resource function devm_kcalloc(), so it will auto free memory when driver is removed.

---
 drivers/gpio/dwapb_gpio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/dwapb_gpio.c +0 -0
index 0f6574d..1594434 100644
@@ -171,8 +171,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
              if (!fdtdec_get_bool(blob, node, "gpio-controller"))
                      continue;
 
Quoted 7 lines

drivers/gpio/dwapb_gpio.c static int gpio_dwapb_bind(struct udevice *dev) · line 176

Quoted 5 lines
drivers/gpio/dwapb_gpio.c +1 -2
-             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()

Yes, you are right. Will fix that.

Thanks.

Regards
Ley Foon