mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Santosh Kumar Yadav" <santoshkumar.yadav@barco.com>
Cc: Peter Korsgaard <peter.korsgaard@barco.com>,
	 Hans de Goede <hansg@kernel.org>,
	Linus Walleij <linusw@kernel.org>,
	 Bartosz Golaszewski <brgl@kernel.org>,
	platform-driver-x86@vger.kernel.org,
	 linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org
Subject: [PATCH v2 2/2] platform/x86: barco-p50-gpio: convert to guard() notation
Date: Wed, 18 Mar 2026 19:56:18 -0700	[thread overview]
Message-ID: <20260318-barco-p50-gpio-set-v2-2-c0a4a6416163@gmail.com> (raw)
In-Reply-To: <20260318-barco-p50-gpio-set-v2-0-c0a4a6416163@gmail.com>

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


  parent reply	other threads:[~2026-03-19  2:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Dmitry Torokhov [this message]
2026-03-19  9:46   ` [PATCH v2 2/2] platform/x86: barco-p50-gpio: convert to guard() notation 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260318-barco-p50-gpio-set-v2-2-c0a4a6416163@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=brgl@kernel.org \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.korsgaard@barco.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=santoshkumar.yadav@barco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®