gpio: gpiolib: use devm_* API to simplify driver code
PATCH 1/1 gpio: gpiolib: use devm_* API to simplify driver code
Use devm_* API to simplify driver code.
--- drivers/gpio/gpiolib.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib.c +5 -6
@@ -243,7 +243,8 @@ int gpiochip_add(struct gpio_chip *chip)int base = chip->base;struct gpio_desc *descs; - descs =kcalloc (chip->ngpio,sizeof (descs[0 ]),GFP_KERNEL ); + descs =devm_kcalloc (chip->dev, chip->ngpio,sizeof (descs[0 ]), +GFP_KERNEL );if (!descs)return -ENOMEM ;
@@ -254,7 +255,7 @@ int gpiochip_add(struct gpio_chip *chip)if (base <0 ) { status = base;spin_unlock_irqrestore (&gpio_lock, flags); - goto err_free_descs; + goto err_descs; } chip->base = base; }
@@ -262,7 +263,7 @@ int gpiochip_add(struct gpio_chip *chip) status =gpiochip_add_to_list (chip);if (status) {spin_unlock_irqrestore (&gpio_lock, flags); - goto err_free_descs; + goto err_descs; }for (id =0 ; id < chip->ngpio; id++) {
@@ -308,9 +309,7 @@ err_remove_chip:list_del (&chip->list);spin_unlock_irqrestore (&gpio_lock, flags); chip->desc =NULL ; -err_free_descs: -kfree (descs); - +err_descs:/* failures here can mean systems won't boot... */ pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__, chip->base, chip->base + chip->ngpio - 1,
Signature · 1 line
1.8.4.5
Quoted 5 lines · Peng Fan
Use devm_* API to simplify driver code.
Signed-off-by Peng Fan <[email protected]>Cc Linus Walleij <[email protected]>Cc Alexandre Courbot <[email protected]>
---
Quoted 8 lines
drivers/gpio/gpiolib.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/gpio/gpiolib.c +0
-0
drivers/gpio/gpiolib.c int gpiochip_add(struct gpio_chip *chip) · line 247
Quoted 6 lines
drivers/gpio/gpiolib.c +2
-1@@ -243,7 +243,8 @@ int gpiochip_add(struct gpio_chip *chip)int base = chip->base;struct gpio_desc *descs; - descs =kcalloc (chip->ngpio,sizeof (descs[0 ]),GFP_KERNEL ); + descs =devm_kcalloc (chip->dev, chip->ngpio,sizeof (descs[0 ]), +GFP_KERNEL );
^ above will not work for every one as NOT all GPIO drivers implemented using dev/drv model, so chip->dev could be not set (at least it was true when I've checked it last time).
Signature · 2 lines
regards, -grygorii
Quoted 21 lines · Grygorii Strashko
Quoted 6 lines · Peng Fan
Use devm_* API to simplify driver code.
Signed-off-by Peng Fan <[email protected]>Cc Linus Walleij <[email protected]>Cc Alexandre Courbot <[email protected]>---
Quoted 12 lines
drivers/gpio/gpiolib.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/gpio/gpiolib.c +0
-0@@ -243,7 +243,8 @@ int gpiochip_add(struct gpio_chip *chip)int base = chip->base;struct gpio_desc *descs;
Quoted 8 lines
drivers/gpio/gpiolib.c int gpiochip_add(struct gpio_chip *chip) · line 247
Quoted 3 lines
drivers/gpio/gpiolib.c +2
-1- descs =kcalloc (chip->ngpio,sizeof (descs[0 ]),GFP_KERNEL ); + descs =devm_kcalloc (chip->dev, chip->ngpio,sizeof (descs[0 ]), +GFP_KERNEL );^ above will not work for every one as NOT all GPIO drivers implemented using dev/drv model, so
chip->devcould be not set (at least it was true when I've checked it last time).
AFAICT that is still true as of today.
Quoted 18 lines · Grygorii Strashko
Quoted 5 lines · Peng Fan
Use devm_* API to simplify driver code.
Signed-off-by Peng Fan <[email protected]>Cc Linus Walleij <[email protected]>Cc Alexandre Courbot <[email protected]>---
Quoted 11 lines
drivers/gpio/gpiolib.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/gpio/gpiolib.c +0
-0@@ -243,7 +243,8 @@ int gpiochip_add(struct gpio_chip *chip)int base = chip->base;struct gpio_desc *descs;
Quoted 8 lines
drivers/gpio/gpiolib.c int gpiochip_add(struct gpio_chip *chip) · line 247
Quoted 3 lines
drivers/gpio/gpiolib.c +2
-1- descs =kcalloc (chip->ngpio,sizeof (descs[0 ]),GFP_KERNEL ); + descs =devm_kcalloc (chip->dev, chip->ngpio,sizeof (descs[0 ]), +GFP_KERNEL );^ above will not work for every one as NOT all GPIO drivers implemented using dev/drv model, so
chip->devcould be not set (at least it was true when I've checked it last time).
Thanks for correcting me!
Regards,
Peng.
Quoted 6 lines
Signature · 3 lines
-- regards, -grygorii