gpiolib: Unify expectations about ->request() returned value
PATCH 1/2 gpiolib: Unify expectations about ->request() returned value
Half of the code in the GPIO library is written in an expectation that any non-zero value returned from the ->request() callback is an error code, while some code checks only for negative values.
Unify expectations about ->request() returned value to be non-zero for an error and 0 for the success.
--- drivers/gpio/gpiolib-sysfs.c | 2 +- drivers/gpio/gpiolib.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib-sysfs.c +1 -1
@@ -476,7 +476,7 @@ static ssize_t export_store(struct class *class,*/ status =gpiod_request (desc,"sysfs" ); -if (status <0 ) { +if (status) {if (status == -EPROBE_DEFER ) status = -ENODEV ; goto done;
drivers/gpio/gpiolib.c +3 -3
@@ -1985,7 +1985,7 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label) ret = -EINVAL ;spin_lock_irqsave (&gpio_lock, flags); -if (ret <0 ) { +if (ret) {desc_set_label (desc,NULL );kfree_const (label);clear_bit (FLAG_REQUESTED , &desc->flags);
@@ -2051,7 +2051,7 @@ int gpiod_request(struct gpio_desc *desc, const char *label)if (try_module_get (gdev->owner)) { ret =gpiod_request_commit (desc, label); -if (ret <0 ) +if (ret)module_put (gdev->owner);else get_device (&gdev->dev);
@@ -3968,7 +3968,7 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,* the device name as label */ ret =gpiod_request (desc, con_id ? con_id : devname); -if (ret <0 ) { +if (ret) {if (ret == -EBUSY && flags &GPIOD_FLAGS_BIT_NONEXCLUSIVE ) {/* * This happens when there are several consumers for
Signature · 1 line
2.28.0
PATCH 2/2 gpiolib: split error path in gpiod_request_commit()
For better maintenance and micro optimization split error path in the gpiod_request_commit().
--- drivers/gpio/gpiolib.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib.c +7 -6
@@ -1968,11 +1968,9 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)if (test_and_set_bit (FLAG_REQUESTED , &desc->flags) ==0 ) {desc_set_label (desc, label ? :"?" ); - ret =0 ; }else { -kfree_const (label); ret = -EBUSY ; - goto done; + goto out_free_unlock; }if (gc->request) {
@@ -1987,9 +1985,8 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)if (ret) {desc_set_label (desc,NULL ); -kfree_const (label);clear_bit (FLAG_REQUESTED , &desc->flags); - goto done; + goto out_free_unlock; } }if (gc->get_direction) {
@@ -1998,8 +1995,12 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)gpiod_get_direction (desc);spin_lock_irqsave (&gpio_lock, flags); } -done:spin_unlock_irqrestore (&gpio_lock, flags); +return 0 ; + +out_free_unlock: +spin_unlock_irqrestore (&gpio_lock, flags); +kfree_const (label);return ret; }
Signature · 1 line
2.28.0
Bartosz Golaszewski
AppliedRe: [PATCH v1 2/2] gpiolib: split error path in gpiod_request_commit()
Quoted 7 lines · Andy Shevchenko
For better maintenance and micro optimization split error path in the
gpiod_request_commit().Signed-off-by Andy Shevchenko <[email protected]>---
Applied, thanks!
Bartosz
Bartosz Golaszewski
AppliedQuoted 10 lines · Andy Shevchenko
Half of the code in the GPIO library is written in an expectation that any non-zero value returned from the ->request() callback is an error code, while some code checks only for negative values.
Unify expectations about ->request() returned value to be non-zero for an error and 0 for the success.
Signed-off-by Andy Shevchenko <[email protected]>---
Applied, thanks!
Bartosz