All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: light: pa12203001: Use guard() to simplify lock handling.
@ 2026-10-26  1:08 Jonathan Cameron
  2026-10-26  9:10 ` Andy Shevchenko
  2026-10-26 17:55 ` Brian Norris
  0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-10-26  1:08 UTC (permalink / raw)
  To: linux-iio, Nuno Sá
  Cc: Brian Norris, Andy Shevchenko, David Lechner, Jonathan Cameron

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


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

end of thread, other threads:[~2026-10-26 17:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-26  1:08 [PATCH] iio: light: pa12203001: Use guard() to simplify lock handling Jonathan Cameron
2026-10-26  9:10 ` Andy Shevchenko
2026-10-26 17:55 ` Brian Norris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.