From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org, "Nuno Sá" <nuno.sa@analog.com>
Cc: Brian Norris <briannorris@chromium.org>,
Andy Shevchenko <andy@kernel.org>,
David Lechner <dlechner@baylibre.com>,
Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Subject: [PATCH] iio: light: pa12203001: Use guard() to simplify lock handling.
Date: Mon, 26 Oct 2026 01:08:03 +0000 [thread overview]
Message-ID: <20261026010803.973666-1-jic23@kernel.org> (raw)
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
It became apparent in reviewing [1] that the use of guard() would
remove some ugly error paths.
Link: https://lore.kernel.org/all/20261021165858.v2.14.I501510b542691f595de1e110cfe35632a5fa7768@changeid/ #[1]
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---
drivers/iio/light/pa12203001.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/drivers/iio/light/pa12203001.c b/drivers/iio/light/pa12203001.c
index 3f5717fb1276..3056ce076239 100644
--- a/drivers/iio/light/pa12203001.c
+++ b/drivers/iio/light/pa12203001.c
@@ -10,6 +10,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/acpi.h>
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
@@ -160,36 +161,29 @@ static int pa12203001_runtime_resume_and_get(struct pa12203001_data *data, u8 ma
int ret;
if (mask & PA12203001_ALS_EN_MASK) {
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
if (data->px_enabled) {
ret = pa12203001_als_enable(data,
PA12203001_ALS_EN_MASK);
if (ret < 0)
- goto err;
+ return ret;
} else {
data->als_needs_enable = true;
}
- mutex_unlock(&data->lock);
}
if (mask & PA12203001_PX_EN_MASK) {
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
if (data->als_enabled) {
ret = pa12203001_px_enable(data, PA12203001_PX_EN_MASK);
if (ret < 0)
- goto err;
+ return ret;
} else {
data->px_needs_enable = true;
}
- mutex_unlock(&data->lock);
}
return pm_runtime_resume_and_get(&data->client->dev);
-
-err:
- mutex_unlock(&data->lock);
- return ret;
-
#endif
return 0;
}
@@ -313,16 +307,12 @@ static int pa12203001_power_chip(struct iio_dev *indio_dev, u8 state)
struct pa12203001_data *data = iio_priv(indio_dev);
int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
ret = pa12203001_als_enable(data, state);
if (ret < 0)
- goto out;
-
- ret = pa12203001_px_enable(data, state);
+ return ret;
-out:
- mutex_unlock(&data->lock);
- return ret;
+ return pa12203001_px_enable(data, state);
}
static int pa12203001_probe(struct i2c_client *client)
@@ -421,7 +411,7 @@ static int pa12203001_runtime_resume(struct device *dev)
data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
if (data->als_needs_enable) {
pa12203001_als_enable(data, PA12203001_ALS_EN_MASK);
data->als_needs_enable = false;
@@ -430,7 +420,6 @@ static int pa12203001_runtime_resume(struct device *dev)
pa12203001_px_enable(data, PA12203001_PX_EN_MASK);
data->px_needs_enable = false;
}
- mutex_unlock(&data->lock);
return 0;
}
--
2.56.0
next reply other threads:[~2026-10-26 1:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 1:08 Jonathan Cameron [this message]
2026-10-26 9:10 ` [PATCH] iio: light: pa12203001: Use guard() to simplify lock handling Andy Shevchenko
2026-10-26 17:55 ` Brian Norris
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=20261026010803.973666-1-jic23@kernel.org \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=briannorris@chromium.org \
--cc=dlechner@baylibre.com \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.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