Skip to contentSkip to conversation

platform/x86: barco-p50-gpio: normalize return value of gpio_get

PATCH Superseded Dmitry Torokhov 3 participants 5 messages Feb 18 – Mar 17

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: barco-p50-gpio: normalize return value of gpio_get

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by p50_gpio_get() is normalized to the [0, 1] range.

---
 drivers/platform/x86/barco-p50-gpio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/barco-p50-gpio.c +4 -1
index 6f13e81f98fb..360ffd8505d6 100644
@@ -275,8 +275,11 @@ static int p50_gpio_get(struct gpio_chip *gc, unsigned int offset)
 	mutex_lock(&p50->lock);
 
 	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_READ_GPIO, gpio_params[offset], 0);
-	if (ret == 0)
+	if (ret == 0) {
 		ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
+		if (ret >= 0)
+			ret = !!ret;
+	}
 
 	mutex_unlock(&p50->lock);
 
Signature · 5 lines
2.53.0.335.g19a08e0c02-goog


-- 
Dmitry
maintainer
#2 lore raw
In reply to Dmitry Torokhov
Quoted 15 lines · Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by p50_gpio_get() is normalized to the [0, 1] range.

---
 drivers/platform/x86/barco-p50-gpio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/barco-p50-gpio.c +0 -0
index 6f13e81f98fb..360ffd8505d6 100644
@@ -275,8 +275,11 @@ static int p50_gpio_get(struct gpio_chip *gc, unsigned int offset)
 	mutex_lock(&p50->lock);

drivers/platform/x86/barco-p50-gpio.c static int p50_gpio_get(struct gpio_chip *gc, unsigned int offset) · line 284

Quoted 10 lines
drivers/platform/x86/barco-p50-gpio.c +4 -1
 
 	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_READ_GPIO, gpio_params[offset], 0);
-	if (ret == 0)
+	if (ret == 0) {
 		ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
+		if (ret >= 0)
+			ret = !!ret;
+	}
 
 	mutex_unlock(&p50->lock);

A simpler flow would be preferrable over all that nesting. Is this logically correct:

	guard(mutex)(p50->lock);
	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_READ_GPIO, gpio_params[offset], 0);
	if (ret < 0)
		return ret;

	ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
	if (ret < 0)
		return ret;

	return !!ret;

?

Signature · 1 line
 i.
#3 lore raw
Quoted 31 lines · Ilpo Järvinen
Quoted 15 lines · Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by p50_gpio_get() is normalized to the [0, 1] range.

---
 drivers/platform/x86/barco-p50-gpio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/barco-p50-gpio.c +0 -0
index 6f13e81f98fb..360ffd8505d6 100644
@@ -275,8 +275,11 @@ static int p50_gpio_get(struct gpio_chip *gc, unsigned int offset)
 	mutex_lock(&p50->lock);

drivers/platform/x86/barco-p50-gpio.c static int p50_gpio_get(struct gpio_chip *gc, unsigned int offset) · line 284

Quoted 10 lines
drivers/platform/x86/barco-p50-gpio.c +4 -1
 
 	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_READ_GPIO, gpio_params[offset], 0);
-	if (ret == 0)
+	if (ret == 0) {
 		ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
+		if (ret >= 0)
+			ret = !!ret;
+	}
 
 	mutex_unlock(&p50->lock);

A simpler flow would be preferrable over all that nesting. Is this logically correct:

Quoted 10 lines
	guard(mutex)(p50->lock);
	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_READ_GPIO, gpio_params[offset], 0);
	if (ret < 0)
		return ret;

	ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
	if (ret < 0)
		return ret;

	return !!ret;

Yes, but I wanted to minimize the amount of change. Maybe I should send a followup patch converting to guard()?

Thanks.

Signature · 1 line
Dmitry
maintainer
#4 lore raw
Quoted 37 lines · Dmitry Torokhov
Quoted 36 lines · Ilpo Järvinen
Quoted 15 lines · Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by p50_gpio_get() is normalized to the [0, 1] range.

---
 drivers/platform/x86/barco-p50-gpio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/barco-p50-gpio.c +0 -0
index 6f13e81f98fb..360ffd8505d6 100644
@@ -275,8 +275,11 @@ static int p50_gpio_get(struct gpio_chip *gc, unsigned int offset)
 	mutex_lock(&p50->lock);

drivers/platform/x86/barco-p50-gpio.c static int p50_gpio_get(struct gpio_chip *gc, unsigned int offset) · line 284

Quoted 10 lines
drivers/platform/x86/barco-p50-gpio.c +4 -1
 
 	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_READ_GPIO, gpio_params[offset], 0);
-	if (ret == 0)
+	if (ret == 0) {
 		ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
+		if (ret >= 0)
+			ret = !!ret;
+	}
 
 	mutex_unlock(&p50->lock);

A simpler flow would be preferrable over all that nesting. Is this logically correct:

	guard(mutex)(p50->lock);
	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_READ_GPIO, gpio_params[offset], 0);
	if (ret < 0)
		return ret;
Quoted 8 lines
Quoted 5 lines
	ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
	if (ret < 0)
		return ret;

	return !!ret;

Yes, but I wanted to minimize the amount of change. Maybe I should send a followup patch converting to guard()?

Please do. I don't want to be adding into complexity when we've a nice solution to simplify it using guard().

Signature · 1 line
 i.