* [PATCH v1 1/2] gpiolib: Unify expectations about ->request() returned value
@ 2020-10-21 11:25 Andy Shevchenko
2020-10-21 11:25 ` [PATCH v1 2/2] gpiolib: split error path in gpiod_request_commit() Andy Shevchenko
2020-10-26 14:44 ` [PATCH v1 1/2] gpiolib: Unify expectations about ->request() returned value Bartosz Golaszewski
0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2020-10-21 11:25 UTC (permalink / raw)
To: Linus Walleij, linux-gpio, Bartosz Golaszewski; +Cc: 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 <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-sysfs.c | 2 +-
drivers/gpio/gpiolib.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index fe580d6b8d0d..f3b886e2132c 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -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;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 4df1f1a23a8b..0e6dddce207d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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
--
2.28.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v1 2/2] gpiolib: split error path in gpiod_request_commit()
2020-10-21 11:25 [PATCH v1 1/2] gpiolib: Unify expectations about ->request() returned value Andy Shevchenko
@ 2020-10-21 11:25 ` Andy Shevchenko
2020-10-26 14:45 ` Bartosz Golaszewski
2020-10-26 14:44 ` [PATCH v1 1/2] gpiolib: Unify expectations about ->request() returned value Bartosz Golaszewski
1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2020-10-21 11:25 UTC (permalink / raw)
To: Linus Walleij, linux-gpio, Bartosz Golaszewski; +Cc: Andy Shevchenko
For better maintenance and micro optimization split error path
in the gpiod_request_commit().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 0e6dddce207d..43ddcf454b5f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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;
}
--
2.28.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/2] gpiolib: Unify expectations about ->request() returned value
2020-10-21 11:25 [PATCH v1 1/2] gpiolib: Unify expectations about ->request() returned value Andy Shevchenko
2020-10-21 11:25 ` [PATCH v1 2/2] gpiolib: split error path in gpiod_request_commit() Andy Shevchenko
@ 2020-10-26 14:44 ` Bartosz Golaszewski
1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2020-10-26 14:44 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Linus Walleij, linux-gpio
On Wed, Oct 21, 2020 at 1:25 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> 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 <andriy.shevchenko@linux.intel.com>
> ---
Applied, thanks!
Bartosz
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-26 14:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-21 11:25 [PATCH v1 1/2] gpiolib: Unify expectations about ->request() returned value Andy Shevchenko
2020-10-21 11:25 ` [PATCH v1 2/2] gpiolib: split error path in gpiod_request_commit() Andy Shevchenko
2020-10-26 14:45 ` Bartosz Golaszewski
2020-10-26 14:44 ` [PATCH v1 1/2] gpiolib: Unify expectations about ->request() returned value Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).