public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: temperature: tsys02d: Use guard(mutex) in tsys02d_write_raw()
@ 2026-04-21 15:40 lauraarakaki
  2026-04-21 17:50 ` Jonathan Cameron
  2026-04-22  7:29 ` Andy Shevchenko
  0 siblings, 2 replies; 4+ messages in thread
From: lauraarakaki @ 2026-04-21 15:40 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy; +Cc: linux-iio

Replace the manual mutex_lock()/mutex_unlock() pair in
tsys02d_write_raw() with guard(mutex)() from the scope-based
cleanup helpers (include/linux/cleanup.h).

The previous code stored the return value of
ms_sensors_write_resolution() in a local variable solely to
bridge the gap between the manual mutex_unlock() call and the
return statement. Using guard(mutex)() removes the need for
both the intermediate variable and the explicit unlock call,
since the mutex is released automatically when the function
goes out of scope.

No functional change intended.

Signed-off-by: lauraarakaki <lauraarakaki23@gmail.com>
---
 drivers/iio/temperature/tsys02d.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/temperature/tsys02d.c b/drivers/iio/temperature/tsys02d.c
index 0cad27205667..55a55f2f4663 100644
--- a/drivers/iio/temperature/tsys02d.c
+++ b/drivers/iio/temperature/tsys02d.c
@@ -10,6 +10,7 @@
  *  http://www.meas-spec.com/downloads/Digital_Sensor_TSYS02D.pdf
  */
 
+#include <linux/cleanup.h>
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
@@ -62,7 +63,7 @@ static int tsys02d_write_raw(struct iio_dev *indio_dev,
 			     int val, int val2, long mask)
 {
 	struct ms_ht_dev *dev_data = iio_priv(indio_dev);
-	int i, ret;
+	int i;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_SAMP_FREQ:
@@ -72,17 +73,13 @@ static int tsys02d_write_raw(struct iio_dev *indio_dev,
 				break;
 		if (i < 0)
 			return -EINVAL;
-		mutex_lock(&dev_data->lock);
+		guard(mutex)(&dev_data->lock);
 		dev_data->res_index = i;
-		ret = ms_sensors_write_resolution(dev_data, i);
-		mutex_unlock(&dev_data->lock);
-
-		return ret;
+		return ms_sensors_write_resolution(dev_data, i);
 	default:
 		return -EINVAL;
 	}
 }
-
 static const struct iio_chan_spec tsys02d_channels[] = {
 	{
 		.type = IIO_TEMP,
-- 
2.47.3


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

end of thread, other threads:[~2026-04-22  7:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 15:40 [PATCH] iio: temperature: tsys02d: Use guard(mutex) in tsys02d_write_raw() lauraarakaki
2026-04-21 17:50 ` Jonathan Cameron
     [not found]   ` <CAJN_CScSHkrXGsF9pjWna5eYnRsPiwj47+7NbVYSVBGkwL3AJw@mail.gmail.com>
2026-04-22  7:26     ` Andy Shevchenko
2026-04-22  7:29 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox