* [PATCH] platform/x86: barco-p50-gpio: normalize return value of gpio_get
@ 2026-02-18 20:58 Dmitry Torokhov
2026-02-19 17:27 ` Linus Walleij
2026-02-23 14:11 ` Ilpo Järvinen
0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Torokhov @ 2026-02-18 20:58 UTC (permalink / raw)
To: Santosh Kumar Yadav
Cc: Peter Korsgaard, Hans de Goede, Ilpo Järvinen, Linus Walleij,
Bartosz Golaszewski, platform-driver-x86, linux-kernel,
linux-gpio
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 <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/barco-p50-gpio.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/barco-p50-gpio.c b/drivers/platform/x86/barco-p50-gpio.c
index 6f13e81f98fb..360ffd8505d6 100644
--- a/drivers/platform/x86/barco-p50-gpio.c
+++ b/drivers/platform/x86/barco-p50-gpio.c
@@ -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);
--
2.53.0.335.g19a08e0c02-goog
--
Dmitry
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] platform/x86: barco-p50-gpio: normalize return value of gpio_get
2026-02-18 20:58 [PATCH] platform/x86: barco-p50-gpio: normalize return value of gpio_get Dmitry Torokhov
@ 2026-02-19 17:27 ` Linus Walleij
2026-02-23 14:11 ` Ilpo Järvinen
1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2026-02-19 17:27 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Santosh Kumar Yadav, Peter Korsgaard, Hans de Goede,
Ilpo Järvinen, Bartosz Golaszewski, platform-driver-x86,
linux-kernel, linux-gpio
On Wed, Feb 18, 2026 at 9:59 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> 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 <dmitry.torokhov@gmail.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] platform/x86: barco-p50-gpio: normalize return value of gpio_get
2026-02-18 20:58 [PATCH] platform/x86: barco-p50-gpio: normalize return value of gpio_get Dmitry Torokhov
2026-02-19 17:27 ` Linus Walleij
@ 2026-02-23 14:11 ` Ilpo Järvinen
2026-03-10 6:18 ` Dmitry Torokhov
1 sibling, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2026-02-23 14:11 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Santosh Kumar Yadav, Peter Korsgaard, Hans de Goede,
Linus Walleij, Bartosz Golaszewski, platform-driver-x86, LKML,
linux-gpio
On Wed, 18 Feb 2026, Dmitry Torokhov wrote:
> 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 <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/barco-p50-gpio.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/barco-p50-gpio.c b/drivers/platform/x86/barco-p50-gpio.c
> index 6f13e81f98fb..360ffd8505d6 100644
> --- a/drivers/platform/x86/barco-p50-gpio.c
> +++ b/drivers/platform/x86/barco-p50-gpio.c
> @@ -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);
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;
?
--
i.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] platform/x86: barco-p50-gpio: normalize return value of gpio_get
2026-02-23 14:11 ` Ilpo Järvinen
@ 2026-03-10 6:18 ` Dmitry Torokhov
2026-03-17 13:25 ` Ilpo Järvinen
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2026-03-10 6:18 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Santosh Kumar Yadav, Peter Korsgaard, Hans de Goede,
Linus Walleij, Bartosz Golaszewski, platform-driver-x86, LKML,
linux-gpio
On Mon, Feb 23, 2026 at 04:11:10PM +0200, Ilpo Järvinen wrote:
> On Wed, 18 Feb 2026, Dmitry Torokhov wrote:
>
> > 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 <dmitry.torokhov@gmail.com>
> > ---
> > drivers/platform/x86/barco-p50-gpio.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/platform/x86/barco-p50-gpio.c b/drivers/platform/x86/barco-p50-gpio.c
> > index 6f13e81f98fb..360ffd8505d6 100644
> > --- a/drivers/platform/x86/barco-p50-gpio.c
> > +++ b/drivers/platform/x86/barco-p50-gpio.c
> > @@ -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);
>
> 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;
Yes, but I wanted to minimize the amount of change. Maybe I should send
a followup patch converting to guard()?
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] platform/x86: barco-p50-gpio: normalize return value of gpio_get
2026-03-10 6:18 ` Dmitry Torokhov
@ 2026-03-17 13:25 ` Ilpo Järvinen
0 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2026-03-17 13:25 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Santosh Kumar Yadav, Peter Korsgaard, Hans de Goede,
Linus Walleij, Bartosz Golaszewski, platform-driver-x86, LKML,
linux-gpio
[-- Attachment #1: Type: text/plain, Size: 1872 bytes --]
On Mon, 9 Mar 2026, Dmitry Torokhov wrote:
> On Mon, Feb 23, 2026 at 04:11:10PM +0200, Ilpo Järvinen wrote:
> > On Wed, 18 Feb 2026, Dmitry Torokhov wrote:
> >
> > > 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 <dmitry.torokhov@gmail.com>
> > > ---
> > > drivers/platform/x86/barco-p50-gpio.c | 5 ++++-
> > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/platform/x86/barco-p50-gpio.c b/drivers/platform/x86/barco-p50-gpio.c
> > > index 6f13e81f98fb..360ffd8505d6 100644
> > > --- a/drivers/platform/x86/barco-p50-gpio.c
> > > +++ b/drivers/platform/x86/barco-p50-gpio.c
> > > @@ -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);
> >
> > 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;
>
> 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().
--
i.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-17 13:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-18 20:58 [PATCH] platform/x86: barco-p50-gpio: normalize return value of gpio_get Dmitry Torokhov
2026-02-19 17:27 ` Linus Walleij
2026-02-23 14:11 ` Ilpo Järvinen
2026-03-10 6:18 ` Dmitry Torokhov
2026-03-17 13:25 ` Ilpo Järvinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox