mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard()
@ 2026-03-19  2:56 Dmitry Torokhov
  2026-03-19  2:56 ` [PATCH v2 1/2] platform/x86: barco-p50-gpio: normalize return value of gpio_get Dmitry Torokhov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2026-03-19  2:56 UTC (permalink / raw)
  To: Ilpo Järvinen, Santosh Kumar Yadav
  Cc: Peter Korsgaard, Hans de Goede, Linus Walleij,
	Bartosz Golaszewski, platform-driver-x86, linux-kernel,
	linux-gpio

These 2 patches fixes a regression in the driver arising from gpiolib
tightening its API, and converts it to guard() notation when taking a
mutex to simplify the code flow.

v2:

- added reviiewed-by and fixes trailers
- added new patch using guard()

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
Dmitry Torokhov (2):
      platform/x86: barco-p50-gpio: normalize return value of gpio_get
      platform/x86: barco-p50-gpio: convert to guard() notation

 drivers/platform/x86/barco-p50-gpio.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
---
base-commit: b84a0ebe421ca56995ff78b66307667b62b3a900
change-id: 20260318-barco-p50-gpio-set-c560daea533e

Thanks.

-- 
Dmitry


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] platform/x86: barco-p50-gpio: normalize return value of gpio_get
  2026-03-19  2:56 [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard() Dmitry Torokhov
@ 2026-03-19  2:56 ` Dmitry Torokhov
  2026-03-19  9:45   ` Bartosz Golaszewski
  2026-03-19  2:56 ` [PATCH v2 2/2] platform/x86: barco-p50-gpio: convert to guard() notation Dmitry Torokhov
  2026-03-23 10:47 ` [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard() Ilpo Järvinen
  2 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2026-03-19  2:56 UTC (permalink / raw)
  To: Ilpo Järvinen, Santosh Kumar Yadav
  Cc: Peter Korsgaard, Hans de Goede, 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.

Fixes: 86ef402d805d606a ("gpiolib: sanitize the return value of gpio_chip::get()")
Reviewed-by: Linus Walleij <linusw@kernel.org>
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.851.ga537e3e6e9-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] platform/x86: barco-p50-gpio: convert to guard() notation
  2026-03-19  2:56 [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard() Dmitry Torokhov
  2026-03-19  2:56 ` [PATCH v2 1/2] platform/x86: barco-p50-gpio: normalize return value of gpio_get Dmitry Torokhov
@ 2026-03-19  2:56 ` Dmitry Torokhov
  2026-03-19  9:46   ` Bartosz Golaszewski
  2026-03-23 10:47 ` [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard() Ilpo Järvinen
  2 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2026-03-19  2:56 UTC (permalink / raw)
  To: Ilpo Järvinen, Santosh Kumar Yadav
  Cc: Peter Korsgaard, Hans de Goede, Linus Walleij,
	Bartosz Golaszewski, platform-driver-x86, linux-kernel,
	linux-gpio

Using guard notation simplifies control flow and makes the code clearer.

Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/platform/x86/barco-p50-gpio.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/platform/x86/barco-p50-gpio.c b/drivers/platform/x86/barco-p50-gpio.c
index 360ffd8505d6..2a6d8607c402 100644
--- a/drivers/platform/x86/barco-p50-gpio.c
+++ b/drivers/platform/x86/barco-p50-gpio.c
@@ -272,33 +272,27 @@ static int p50_gpio_get(struct gpio_chip *gc, unsigned int offset)
 	struct p50_gpio *p50 = gpiochip_get_data(gc);
 	int ret;
 
-	mutex_lock(&p50->lock);
+	guard(mutex)(&p50->lock);
 
 	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_READ_GPIO, gpio_params[offset], 0);
-	if (ret == 0) {
-		ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
-		if (ret >= 0)
-			ret = !!ret;
-	}
+	if (ret < 0)
+		return ret;
 
-	mutex_unlock(&p50->lock);
+	ret = p50_read_mbox_reg(p50, P50_MBOX_REG_DATA);
+	if (ret < 0)
+		return ret;
 
-	return ret;
+	return !!ret;
 }
 
 static int p50_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
 {
 	struct p50_gpio *p50 = gpiochip_get_data(gc);
-	int ret;
-
-	mutex_lock(&p50->lock);
 
-	ret = p50_send_mbox_cmd(p50, P50_MBOX_CMD_WRITE_GPIO,
-				gpio_params[offset], value);
+	guard(mutex)(&p50->lock);
 
-	mutex_unlock(&p50->lock);
-
-	return ret;
+	return p50_send_mbox_cmd(p50, P50_MBOX_CMD_WRITE_GPIO,
+				 gpio_params[offset], value);
 }
 
 static int p50_gpio_probe(struct platform_device *pdev)

-- 
2.53.0.851.ga537e3e6e9-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] platform/x86: barco-p50-gpio: normalize return value of gpio_get
  2026-03-19  2:56 ` [PATCH v2 1/2] platform/x86: barco-p50-gpio: normalize return value of gpio_get Dmitry Torokhov
@ 2026-03-19  9:45   ` Bartosz Golaszewski
  0 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2026-03-19  9:45 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Peter Korsgaard, Hans de Goede, Linus Walleij,
	Bartosz Golaszewski, platform-driver-x86, linux-kernel,
	linux-gpio, Ilpo Järvinen, Santosh Kumar Yadav

On Thu, 19 Mar 2026 03:56:17 +0100, Dmitry Torokhov
<dmitry.torokhov@gmail.com> said:
> 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.
>
> Fixes: 86ef402d805d606a ("gpiolib: sanitize the return value of gpio_chip::get()")
> Reviewed-by: Linus Walleij <linusw@kernel.org>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] platform/x86: barco-p50-gpio: convert to guard() notation
  2026-03-19  2:56 ` [PATCH v2 2/2] platform/x86: barco-p50-gpio: convert to guard() notation Dmitry Torokhov
@ 2026-03-19  9:46   ` Bartosz Golaszewski
  0 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2026-03-19  9:46 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Peter Korsgaard, Hans de Goede, Linus Walleij,
	Bartosz Golaszewski, platform-driver-x86, linux-kernel,
	linux-gpio, Ilpo Järvinen, Santosh Kumar Yadav

On Thu, 19 Mar 2026 03:56:18 +0100, Dmitry Torokhov
<dmitry.torokhov@gmail.com> said:
> Using guard notation simplifies control flow and makes the code clearer.
>
> Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard()
  2026-03-19  2:56 [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard() Dmitry Torokhov
  2026-03-19  2:56 ` [PATCH v2 1/2] platform/x86: barco-p50-gpio: normalize return value of gpio_get Dmitry Torokhov
  2026-03-19  2:56 ` [PATCH v2 2/2] platform/x86: barco-p50-gpio: convert to guard() notation Dmitry Torokhov
@ 2026-03-23 10:47 ` Ilpo Järvinen
  2 siblings, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2026-03-23 10:47 UTC (permalink / raw)
  To: Santosh Kumar Yadav, Dmitry Torokhov
  Cc: Peter Korsgaard, Hans de Goede, Linus Walleij,
	Bartosz Golaszewski, platform-driver-x86, linux-kernel,
	linux-gpio

On Wed, 18 Mar 2026 19:56:16 -0700, Dmitry Torokhov wrote:

> These 2 patches fixes a regression in the driver arising from gpiolib
> tightening its API, and converts it to guard() notation when taking a
> mutex to simplify the code flow.
> 
> v2:
> 
> - added reviiewed-by and fixes trailers
> - added new patch using guard()
> 
> [...]


Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/2] platform/x86: barco-p50-gpio: normalize return value of gpio_get
      commit: 1c9d30d37aaffe3454d70b89a77f8aaecda257bf
[2/2] platform/x86: barco-p50-gpio: convert to guard() notation
      commit: a5877e921389178f994a5ec15a145d7e7ba3ec65

--
 i.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-23 10:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-19  2:56 [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard() Dmitry Torokhov
2026-03-19  2:56 ` [PATCH v2 1/2] platform/x86: barco-p50-gpio: normalize return value of gpio_get Dmitry Torokhov
2026-03-19  9:45   ` Bartosz Golaszewski
2026-03-19  2:56 ` [PATCH v2 2/2] platform/x86: barco-p50-gpio: convert to guard() notation Dmitry Torokhov
2026-03-19  9:46   ` Bartosz Golaszewski
2026-03-23 10:47 ` [PATCH v2 0/2] barco-p50-gpio: normalize return value of "get" and convert to guard() 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

all inboxes | Powered by JetHome®