gpio: make gpiod_count() API consistent
Subsystems (4)
cover gpio: make gpiod_count() API consistent
There are three possibilities in gpiod_count(): ACPI, OF, and platform data.
Some of them return 0, which requires to be handled separately, though developers rather lazy and just shadow an actual error code.
Let's make this API consistent by not allowing 0 in returned value.
There are luckily only 3 users right now, one of them handles this properly, the rest is converted in this series.
Series is supposed to go through GPIO tree.
Andy Shevchenko (4):
gpio: acpi: Don't return 0 on acpi_gpio_count()
gpio: of: Don't return 0 on dt_gpio_count() platform/x86: surface3_button: Propagate error from gpiod_count()
Input: soc_button_array - Propagate error from gpiod_count()
drivers/gpio/gpiolib-acpi.c | 4 ++-- drivers/gpio/gpiolib.c | 4 ++-- drivers/input/misc/soc_button_array.c | 5 +++-- drivers/platform/x86/surface3_button.c | 5 +++-- 4 files changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/4 gpio: acpi: Don't return 0 on acpi_gpio_count()
It's unusual to have error checking like (ret <= 0) in cases when counting GPIO resources. In case when it's mandatory we propagate the error (-ENOENT), otherwise we don't use the result.
This makes consistent behaviour across all possible variants called in gpiod_count().
--- drivers/gpio/gpiolib-acpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib-acpi.c +2 -2
@@ -1067,7 +1067,7 @@ int acpi_gpio_count(struct device *dev, const char *con_id)break ; } } -if (count >=0 ) +if (count >0 )break ; }
@@ -1083,7 +1083,7 @@ int acpi_gpio_count(struct device *dev, const char *con_id)if (crs_count >0 ) count = crs_count; } -return count; +return count ? count : -ENOENT ; }struct acpi_crs_lookup {
Signature · 1 line
2.11.0
PATCH 2/4 gpio: of: Don't return 0 on dt_gpio_count()
In reply to Andy ShevchenkoIt's unusual to have error checking like (ret <= 0) in cases when counting GPIO resources. In case when it's mandatory we propagate the error (-ENOENT), otherwise we don't use the result.
This makes consistent behaviour across all possible variants called in gpiod_count().
--- drivers/gpio/gpiolib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +2 -2
@@ -3122,10 +3122,10 @@ static int dt_gpio_count(struct device *dev, const char *con_id) gpio_suffixes[i]); ret =of_gpio_named_count (dev->of_node, propname); -if (ret >=0 ) +if (ret >0 )break ; } -return ret; +return ret ? ret : -ENOENT ; }static int platform_gpio_count (struct device *dev,const char *con_id)
Signature · 1 line
2.11.0
PATCH 3/4 platform/x86: surface3_button: Propagate error from gpiod_count()
In reply to Andy ShevchenkoSince gpiod_count() does not return 0 anymore, we don't need to shadow its error code and would safely propagate to the user.
While here, replace second parameter by NULL in order to prevent side effects on _DSD enabled firmware.
--- drivers/platform/x86/surface3_button.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/surface3_button.c +3 -2
@@ -196,9 +196,10 @@ static int surface3_button_probe(struct i2c_client *client, strlen(SURFACE_BUTTON_OBJ_NAME)))return -ENODEV ; -if (gpiod_count (dev,KBUILD_MODNAME ) <=0 ) { + error =gpiod_count (dev,NULL ); +if (error <0 ) {dev_dbg (dev,"no GPIO attached, ignoring...\n" ); -return -ENODEV ; +return error; } priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
Signature · 1 line
2.11.0
PATCH 4/4 Input: soc_button_array - Propagate error from gpiod_count()
In reply to Andy ShevchenkoSince gpiod_count() does not return 0 anymore, we don't need to shadow its error code and would safely propagate to the user.
While here, replace second parameter by NULL in order to prevent side effects on _DSD enabled firmware.
--- drivers/input/misc/soc_button_array.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/misc/soc_button_array.c +3 -2
@@ -169,9 +169,10 @@ static int soc_button_probe(struct platform_device *pdev) button_info = (struct soc_button_info *)id->driver_data; -if (gpiod_count (dev,KBUILD_MODNAME ) <=0 ) { + error =gpiod_count (dev,NULL ); +if (error <0 ) {dev_dbg (dev,"no GPIO attached, ignoring...\n" ); -return -ENODEV ; +return error; } priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
Signature · 1 line
2.11.0
Re: [PATCH v1 4/4] Input: soc_button_array - Propagate error from gpiod_count()
Quoted 8 lines · Andy Shevchenko
Since
gpiod_count()does not return 0 anymore, we don't need to shadow its error code and would safely propagate to the user.While here, replace second parameter by NULL in order to prevent side effects on
_DSDenabled firmware.Cc Benjamin Tissoires <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Quoted 24 lines
--- drivers/input/misc/soc_button_array.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/input/misc/soc_button_array.c +3
-2@@ -169,9 +169,10 @@ static int soc_button_probe(struct platform_device *pdev) button_info = (struct soc_button_info *)id->driver_data; -if (gpiod_count (dev,KBUILD_MODNAME ) <=0 ) { + error =gpiod_count (dev,NULL ); +if (error <0 ) {dev_dbg (dev,"no GPIO attached, ignoring...\n" ); -return -ENODEV ; +return error; } priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );Signature · 1 line
2.11.0
Signature · 1 line
Dmitry
Quoted 11 lines · Andy Shevchenko
There are three possibilities in
gpiod_count(): ACPI, OF, and platform data.Some of them return 0, which requires to be handled separately, though developers rather lazy and just shadow an actual error code.
Let's make this API consistent by not allowing 0 in returned value.
There are luckily only 3 users right now, one of them handles this properly, the rest is converted in this series.
Quoted 7 lines
Series is supposed to go through GPIO tree.
Andy Shevchenko (4):
gpio: acpi: Don't return 0 onacpi_gpio_count()
gpio: of: Don't return 0 ondt_gpio_count()platform/x86:surface3_button: Propagate error fromgpiod_count()
Input:soc_button_array- Propagate error fromgpiod_count()
Not sure if this still matters, but still:
Cheers,
Benjamin
Quoted 10 lines
drivers/gpio/gpiolib-acpi.c | 4 ++-- drivers/gpio/gpiolib.c | 4 ++-- drivers/input/misc/soc_button_array.c | 5 +++-- drivers/platform/x86/surface3_button.c | 5 +++-- 4 files changed, 10 insertions(+), 8 deletions(-)Signature · 1 line
2.11.0
Quoted 15 lines · Benjamin Tissoires
Quoted 14 lines · Andy Shevchenko
There are three possibilities in
gpiod_count(): ACPI, OF, and platform data.Some of them return 0, which requires to be handled separately, though
developers rather lazy and just shadow an actual error code.Let's make this API consistent by not allowing 0 in returned value.
There are luckily only 3 users right now, one of them handles this properly, the rest is converted in this series.
Series is supposed to go through GPIO tree.
Quoted 8 lines
Quoted 5 lines
Andy Shevchenko (4):
gpio: acpi: Don't return 0 onacpi_gpio_count()
gpio: of: Don't return 0 ondt_gpio_count()platform/x86:surface3_button: Propagate error fromgpiod_count()
Input:soc_button_array- Propagate error fromgpiod_count()Not sure if this still matters, but still:
I'm sure it is.
Linus, is your plan to go through queue after merge window is closed?
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v1 1/4] gpio: acpi: Don't return 0 on acpi_gpio_count()
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
It's unusual to have error checking like (ret <= 0) in cases when counting GPIO resources. In case when it's mandatory we propagate the error (
-ENOENT), otherwise we don't use the result.This makes consistent behaviour across all possible variants called in
gpiod_count().Signed-off-by Andy Shevchenko <[email protected]>
Mika/Rafael, can you look at this patch?
(Andy: sorry for late reply, busy merge window...)
Yours,
Linus Walleij
Re: [PATCH v1 3/4] platform/x86: surface3_button: Propagate error from gpiod_count()
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
Since
gpiod_count()does not return 0 anymore, we don't need to shadow its error code and would safely propagate to the user.While here, replace second parameter by NULL in order to prevent side effects on
_DSDenabled firmware.Cc Benjamin Tissoires <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
As I understand it Andy, you're more or less default-maintainer for drivers/platform/x86 so I can just merge this patch into the GPIO tree with the rest?
Yours,
Linus Walleij
Quoted 22 lines · Andy Shevchenko
Quoted 21 lines · Benjamin Tissoires
Quoted 19 lines · Andy Shevchenko
There are three possibilities in
gpiod_count(): ACPI, OF, and platform data.Some of them return 0, which requires to be handled separately, though
developers rather lazy and just shadow an actual error code.Let's make this API consistent by not allowing 0 in returned value.
There are luckily only 3 users right now, one of them handles this properly, the rest is converted in this series.
Series is supposed to go through GPIO tree.
Andy Shevchenko (4):
gpio: acpi: Don't return 0 onacpi_gpio_count()
gpio: of: Don't return 0 ondt_gpio_count()platform/x86:surface3_button: Propagate error fromgpiod_count()
Input:soc_button_array- Propagate error fromgpiod_count()
Quoted 6 lines
Quoted 2 lines
Not sure if this still matters, but still:
I'm sure it is.
Linus, is your plan to go through queue after merge window is closed?
Yes sorry for the delay, it was a busy merge window etc.
I'd like to have some nod from Mika/Rafael that this is what we want to do. If I don't hear anything I guess I will just merge them, it looks right to me.
Yours,
Linus Walleij
Mika Westerberg
Acked-byRe: [PATCH v1 1/4] gpio: acpi: Don't return 0 on acpi_gpio_count()
In reply to Linus WalleijQuoted 7 lines · Linus Walleij
Quoted 4 lines · Andy Shevchenko
It's unusual to have error checking like (ret <= 0) in cases when counting GPIO resources. In case when it's mandatory we propagate the error (
-ENOENT), otherwise we don't use the result.
Quoted 6 lines
Quoted 4 lines
This makes consistent behaviour across all possible variants called in
gpiod_count().Signed-off-by Andy Shevchenko <[email protected]>Mika/Rafael, can you look at this patch?
Re: [PATCH v1 3/4] platform/x86: surface3_button: Propagate error from gpiod_count()
In reply to Linus WalleijQuoted 11 lines · Linus Walleij
Quoted 8 lines · Andy Shevchenko
Since
gpiod_count()does not return 0 anymore, we don't need to shadow
its error code and would safely propagate to the user.While here, replace second parameter by NULL in order to prevent side
effects on_DSDenabled firmware.
Quoted 6 lines
Quoted 2 lines
Cc Benjamin Tissoires <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>As I understand it Andy, you're more or less default-maintainer for
drivers/platform/x86so I can just merge this patch into the GPIO tree with the rest?
Correct!
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH v1 1/4] gpio: acpi: Don't return 0 on acpi_gpio_count()
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
It's unusual to have error checking like (ret <= 0) in cases when counting GPIO resources. In case when it's mandatory we propagate the error (
-ENOENT), otherwise we don't use the result.This makes consistent behaviour across all possible variants called in
gpiod_count().Signed-off-by Andy Shevchenko <[email protected]>
Patch applied with Mika's ACK.
Yours,
Linus Walleij
Re: [PATCH v1 2/4] gpio: of: Don't return 0 on dt_gpio_count()
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
It's unusual to have error checking like (ret <= 0) in cases when counting GPIO resources. In case when it's mandatory we propagate the error (
-ENOENT), otherwise we don't use the result.This makes consistent behaviour across all possible variants called in
gpiod_count().Signed-off-by Andy Shevchenko <[email protected]>
Patch applied.
Yours,
Linus Walleij
Re: [PATCH v1 3/4] platform/x86: surface3_button: Propagate error from gpiod_count()
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
Since
gpiod_count()does not return 0 anymore, we don't need to shadow its error code and would safely propagate to the user.While here, replace second parameter by NULL in order to prevent side effects on
_DSDenabled firmware.Cc Benjamin Tissoires <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Patch applied to the GPIO tree.
Yours,
Linus Walleij
Re: [PATCH v1 4/4] Input: soc_button_array - Propagate error from gpiod_count()
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
Since
gpiod_count()does not return 0 anymore, we don't need to shadow its error code and would safely propagate to the user.While here, replace second parameter by NULL in order to prevent side effects on
_DSDenabled firmware.Cc Benjamin Tissoires <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Patch applied with Dmitry's ACK.
Yours,
Linus Walleij