platform/x86: barco-p50-gpio: normalize return value of gpio_get
Subsystems (3)
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
@@ -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
Quoted 5 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.Signed-off-by Dmitry Torokhov <[email protected]>
Yours,
Linus Walleij
Ilpo Järvinen
maintainerQuoted 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.Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/platform/x86/barco-p50-gpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/platform/x86/barco-p50-gpio.c +0
-0@@ -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
-1ret =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.
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.Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/platform/x86/barco-p50-gpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/platform/x86/barco-p50-gpio.c +0
-0@@ -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
-1ret =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
Ilpo Järvinen
maintainerQuoted 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.Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/platform/x86/barco-p50-gpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/platform/x86/barco-p50-gpio.c +0
-0@@ -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
-1ret =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.