Skip to contentSkip to conversation

gpio: make gpiod_count() API consistent

PATCH In review Andy Shevchenko 5 participants 17 messages Feb 20, 2017 – Mar 16, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 9b37a3692b3f..d7a22c470312 100644
@@ -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
#5 lore raw

PATCH 2/4 gpio: of: Don't return 0 on dt_gpio_count()

In reply to 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().

---
 drivers/gpio/gpiolib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +2 -2
index 8b4d721d6d63..f8ee417de0b7 100644
@@ -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
#7 lore raw

PATCH 3/4 platform/x86: surface3_button: Propagate error from gpiod_count()

In reply to 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 _DSD enabled firmware.

Cc Benjamin Tissoires <[email protected]>
---
 drivers/platform/x86/surface3_button.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/surface3_button.c +3 -2
index 8bfd7f613d36..57f51476bb65 100644
@@ -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
#11 lore raw

PATCH 4/4 Input: soc_button_array - Propagate error from gpiod_count()

In reply to 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 _DSD enabled firmware.

Cc Benjamin Tissoires <[email protected]>
---
 drivers/input/misc/soc_button_array.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/misc/soc_button_array.c +3 -2
index ddb2f22fca7a..c3b8e1fb4699 100644
@@ -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
maintainer Acked-by on v1 4/4
#12 lore raw

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 _DSD enabled firmware.

Cc Benjamin Tissoires <[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
index ddb2f22fca7a..c3b8e1fb4699 100644
@@ -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
Acked-by on the v1 series
#14 lore raw
In reply to Andy Shevchenko
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 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()

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
#15 lore raw
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 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()

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
#2 lore raw

Re: [PATCH v1 1/4] gpio: acpi: Don't return 0 on acpi_gpio_count()

In reply to Andy Shevchenko
Quoted 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().

Mika/Rafael, can you look at this patch?

(Andy: sorry for late reply, busy merge window...)

Yours,
Linus Walleij

#8 lore raw

Re: [PATCH v1 3/4] platform/x86: surface3_button: Propagate error from gpiod_count()

In reply to Andy Shevchenko
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 _DSD enabled firmware.

Cc Benjamin Tissoires <[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

#16 lore raw
In reply to Andy Shevchenko
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 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()

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

#3 lore raw

Re: [PATCH v1 1/4] gpio: acpi: Don't return 0 on acpi_gpio_count()

In reply to Linus Walleij
Quoted 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().

Mika/Rafael, can you look at this patch?

#9 lore raw

Re: [PATCH v1 3/4] platform/x86: surface3_button: Propagate error from gpiod_count()

In reply to Linus Walleij
Quoted 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 _DSD enabled firmware.

Quoted 6 lines
Quoted 2 lines
Cc Benjamin Tissoires <[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?

Correct!

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#4 lore raw

Re: [PATCH v1 1/4] gpio: acpi: Don't return 0 on acpi_gpio_count()

In reply to Andy Shevchenko
Quoted 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().

Patch applied with Mika's ACK.

Yours,
Linus Walleij

#6 lore raw

Re: [PATCH v1 2/4] gpio: of: Don't return 0 on dt_gpio_count()

In reply to Andy Shevchenko
Quoted 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().

Patch applied.

Yours,
Linus Walleij

#10 lore raw

Re: [PATCH v1 3/4] platform/x86: surface3_button: Propagate error from gpiod_count()

In reply to Andy Shevchenko
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 _DSD enabled firmware.

Cc Benjamin Tissoires <[email protected]>

Patch applied to the GPIO tree.

Yours,
Linus Walleij

#13 lore raw

Re: [PATCH v1 4/4] Input: soc_button_array - Propagate error from gpiod_count()

In reply to Andy Shevchenko
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 _DSD enabled firmware.

Cc Benjamin Tissoires <[email protected]>

Patch applied with Dmitry's ACK.

Yours,
Linus Walleij