* [PATCH] iio: common: ms_sensors: use guard(mutex) helper
@ 2026-04-16 3:23 Giovanna Luisa Hirata dos Anjos
2026-04-17 8:31 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Giovanna Luisa Hirata dos Anjos @ 2026-04-16 3:23 UTC (permalink / raw)
To: jic23, dlechner, nuno.sa, andy
Cc: Giovanna Luisa Hirata dos Anjos, Naili Lucia Marques, linux-iio
The guard(mutex) macro helps to simplify the code by automatically
releasing the mutex when the dev_data->lock variable goes out of scope.
This reduces the risk of forgetting to call mutex_unlock in error paths.
Refactor all functions in this driver to use this modern cleanup helper.
Signed-off-by: Giovanna Luisa Hirata dos Anjos <giovannaluisahirata@usp.br>
Co-developed-by: Naili Lucia Marques <naahmarque345@usp.br>
Signed-off-by: Naili Lucia Marques <naahmarque345@usp.br>
---
.../iio/common/ms_sensors/ms_sensors_i2c.c | 22 +++++++------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.c b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c
index 1960a2ce82a8..4dc9ec349dc6 100644
--- a/drivers/iio/common/ms_sensors/ms_sensors_i2c.c
+++ b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c
@@ -9,6 +9,7 @@
#include <linux/iio/iio.h>
#include <linux/device.h>
#include <linux/delay.h>
+#include <linux/cleanup.h>
#include "ms_sensors_i2c.h"
@@ -318,9 +319,8 @@ ssize_t ms_sensors_show_battery_low(struct ms_ht_dev *dev_data,
int ret;
u8 config_reg;
- mutex_lock(&dev_data->lock);
+ guard(mutex)(&dev_data->lock);
ret = ms_sensors_read_config_reg(dev_data->client, &config_reg);
- mutex_unlock(&dev_data->lock);
if (ret)
return ret;
@@ -345,9 +345,8 @@ ssize_t ms_sensors_show_heater(struct ms_ht_dev *dev_data,
u8 config_reg;
int ret;
- mutex_lock(&dev_data->lock);
+ guard(mutex)(&dev_data->lock);
ret = ms_sensors_read_config_reg(dev_data->client, &config_reg);
- mutex_unlock(&dev_data->lock);
if (ret)
return ret;
@@ -380,10 +379,9 @@ ssize_t ms_sensors_write_heater(struct ms_ht_dev *dev_data,
if (val > 1)
return -EINVAL;
- mutex_lock(&dev_data->lock);
+ guard(mutex)(&dev_data->lock);
ret = ms_sensors_read_config_reg(dev_data->client, &config_reg);
if (ret) {
- mutex_unlock(&dev_data->lock);
return ret;
}
@@ -393,7 +391,6 @@ ssize_t ms_sensors_write_heater(struct ms_ht_dev *dev_data,
ret = i2c_smbus_write_byte_data(dev_data->client,
MS_SENSORS_CONFIG_REG_WRITE,
config_reg);
- mutex_unlock(&dev_data->lock);
if (ret) {
dev_err(&dev_data->client->dev, "Unable to write config register\n");
return ret;
@@ -421,13 +418,12 @@ int ms_sensors_ht_read_temperature(struct ms_ht_dev *dev_data,
u32 adc;
u16 delay;
- mutex_lock(&dev_data->lock);
+ guard(mutex)(&dev_data->lock);
delay = ms_sensors_ht_t_conversion_time[dev_data->res_index];
ret = ms_sensors_convert_and_read(dev_data->client,
MS_SENSORS_HT_T_CONVERSION_START,
MS_SENSORS_NO_READ_CMD,
delay, &adc);
- mutex_unlock(&dev_data->lock);
if (ret)
return ret;
@@ -462,13 +458,12 @@ int ms_sensors_ht_read_humidity(struct ms_ht_dev *dev_data,
u32 adc;
u16 delay;
- mutex_lock(&dev_data->lock);
+ guard(mutex)(&dev_data->lock);
delay = ms_sensors_ht_h_conversion_time[dev_data->res_index];
ret = ms_sensors_convert_and_read(dev_data->client,
MS_SENSORS_HT_H_CONVERSION_START,
MS_SENSORS_NO_READ_CMD,
delay, &adc);
- mutex_unlock(&dev_data->lock);
if (ret)
return ret;
@@ -625,7 +620,7 @@ int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,
s64 off, sens, t2, off2, sens2;
u16 *prom = dev_data->prom, delay;
- mutex_lock(&dev_data->lock);
+ guard(mutex)(&dev_data->lock);
delay = ms_sensors_tp_conversion_time[dev_data->res_index];
ret = ms_sensors_convert_and_read(
@@ -635,7 +630,6 @@ int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,
MS_SENSORS_TP_ADC_READ,
delay, &t_adc);
if (ret) {
- mutex_unlock(&dev_data->lock);
return ret;
}
@@ -645,7 +639,7 @@ int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,
dev_data->res_index * 2,
MS_SENSORS_TP_ADC_READ,
delay, &p_adc);
- mutex_unlock(&dev_data->lock);
+
if (ret)
return ret;
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: common: ms_sensors: use guard(mutex) helper
2026-04-16 3:23 [PATCH] iio: common: ms_sensors: use guard(mutex) helper Giovanna Luisa Hirata dos Anjos
@ 2026-04-17 8:31 ` Andy Shevchenko
2026-04-20 22:52 ` Giovanna Luisa Hirata dos Anjos
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-04-17 8:31 UTC (permalink / raw)
To: Giovanna Luisa Hirata dos Anjos
Cc: jic23, dlechner, nuno.sa, andy, Naili Lucia Marques, linux-iio
On Thu, Apr 16, 2026 at 12:23:45AM -0300, Giovanna Luisa Hirata dos Anjos wrote:
> The guard(mutex) macro helps to simplify the code by automatically
> releasing the mutex when the dev_data->lock variable goes out of scope.
> This reduces the risk of forgetting to call mutex_unlock in error paths.
>
> Refactor all functions in this driver to use this modern cleanup helper.
Please, read my comments to your other changes. Slow down with the submissions
of a new one until we settle on the rest, you will develop the style that will
be accepted in the future without comments.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: common: ms_sensors: use guard(mutex) helper
2026-04-17 8:31 ` Andy Shevchenko
@ 2026-04-20 22:52 ` Giovanna Luisa Hirata dos Anjos
2026-04-22 6:57 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Giovanna Luisa Hirata dos Anjos @ 2026-04-20 22:52 UTC (permalink / raw)
To: Andy Shevchenko
Cc: jic23, dlechner, nuno.sa, andy, Naili Lucia Marques, linux-iio
Hi Andy,
Thank you for the feedback.
Regarding the other changes, we believe there might be a
misunderstanding, as this is our first submission to the list. We've
checked lore and only found this specific thread:
https://lore.kernel.org/all/?q=f%3Agiovanna+luisa+hirata
As newcomers, we appreciate the guidance and will follow your
suggestion to slow down and refine our style before further
submissions.
I have already reordered the includes alphabetically and will send a
v2 once the current discussion settles.
Best regards,
Giovanna
Em sex., 17 de abr. de 2026 às 05:31, Andy Shevchenko
<andriy.shevchenko@intel.com> escreveu:
>
> On Thu, Apr 16, 2026 at 12:23:45AM -0300, Giovanna Luisa Hirata dos Anjos wrote:
> > The guard(mutex) macro helps to simplify the code by automatically
> > releasing the mutex when the dev_data->lock variable goes out of scope.
> > This reduces the risk of forgetting to call mutex_unlock in error paths.
> >
> > Refactor all functions in this driver to use this modern cleanup helper.
>
> Please, read my comments to your other changes. Slow down with the submissions
> of a new one until we settle on the rest, you will develop the style that will
> be accepted in the future without comments.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: common: ms_sensors: use guard(mutex) helper
2026-04-20 22:52 ` Giovanna Luisa Hirata dos Anjos
@ 2026-04-22 6:57 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-04-22 6:57 UTC (permalink / raw)
To: Giovanna Luisa Hirata dos Anjos
Cc: jic23, dlechner, nuno.sa, andy, Naili Lucia Marques, linux-iio
On Mon, Apr 20, 2026 at 07:52:25PM -0300, Giovanna Luisa Hirata dos Anjos wrote:
Please, do not top-post!
> Thank you for the feedback.
>
> Regarding the other changes, we believe there might be a
> misunderstanding, as this is our first submission to the list. We've
> checked lore and only found this specific thread:
> https://lore.kernel.org/all/?q=f%3Agiovanna+luisa+hirata
>
> As newcomers, we appreciate the guidance and will follow your
> suggestion to slow down and refine our style before further
> submissions.
>
> I have already reordered the includes alphabetically and will send a
> v2 once the current discussion settles.
So many patches lately with similar content... It may be I mixed yours with
somebody's else. The outcome of it is obvious lack of reviewing the code *by
newcomers* (by humans in other words). I am now starting thinking that newcomers
has to review at least 10 patches on the topic (subsystem) before submit their
first one. This will train more on the process, and other useful skills.
> Em sex., 17 de abr. de 2026 às 05:31, Andy Shevchenko
> <andriy.shevchenko@intel.com> escreveu:
> >
> > On Thu, Apr 16, 2026 at 12:23:45AM -0300, Giovanna Luisa Hirata dos Anjos wrote:
> > > The guard(mutex) macro helps to simplify the code by automatically
> > > releasing the mutex when the dev_data->lock variable goes out of scope.
> > > This reduces the risk of forgetting to call mutex_unlock in error paths.
> > >
> > > Refactor all functions in this driver to use this modern cleanup helper.
> >
> > Please, read my comments to your other changes. Slow down with the submissions
> > of a new one until we settle on the rest, you will develop the style that will
> > be accepted in the future without comments.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-22 6:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16 3:23 [PATCH] iio: common: ms_sensors: use guard(mutex) helper Giovanna Luisa Hirata dos Anjos
2026-04-17 8:31 ` Andy Shevchenko
2026-04-20 22:52 ` Giovanna Luisa Hirata dos Anjos
2026-04-22 6:57 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox