Use guard(mutex) in a couple of functions to allow direct returns. This
simplifies the code a bit and will make later changes easier.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad7124.c | 35 ++++++++++++-----------------------
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 97d601b3387524fe411cc0afc736618e32759880..3afc4dcc315e82ab822370ff8d21590086e0bc7e 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -739,24 +739,20 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
{
struct ad7124_state *st = iio_priv(indio_dev);
unsigned int res, gain, full_scale, vref;
- int ret = 0;
- mutex_lock(&st->cfgs_lock);
+ guard(mutex)(&st->cfgs_lock);
switch (info) {
case IIO_CHAN_INFO_SAMP_FREQ:
- if (val2 != 0 || val == 0) {
- ret = -EINVAL;
- break;
- }
+ if (val2 != 0 || val == 0)
+ return -EINVAL;
ad7124_set_channel_odr(st, chan->address, val);
- break;
+
+ return 0;
case IIO_CHAN_INFO_SCALE:
- if (val != 0) {
- ret = -EINVAL;
- break;
- }
+ if (val != 0)
+ return -EINVAL;
if (st->channels[chan->address].cfg.bipolar)
full_scale = 1 << (chan->scan_type.realbits - 1);
@@ -772,13 +768,10 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
st->channels[chan->address].cfg.live = false;
st->channels[chan->address].cfg.pga_bits = res;
- break;
+ return 0;
default:
- ret = -EINVAL;
+ return -EINVAL;
}
-
- mutex_unlock(&st->cfgs_lock);
- return ret;
}
static int ad7124_reg_access(struct iio_dev *indio_dev,
@@ -810,7 +803,8 @@ static int ad7124_update_scan_mode(struct iio_dev *indio_dev,
int ret;
int i;
- mutex_lock(&st->cfgs_lock);
+ guard(mutex)(&st->cfgs_lock);
+
for (i = 0; i < st->num_channels; i++) {
bit_set = test_bit(i, scan_mask);
if (bit_set)
@@ -818,15 +812,10 @@ static int ad7124_update_scan_mode(struct iio_dev *indio_dev,
else
ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_ENABLE,
0, 2);
- if (ret < 0) {
- mutex_unlock(&st->cfgs_lock);
-
+ if (ret < 0)
return ret;
- }
}
- mutex_unlock(&st->cfgs_lock);
-
return 0;
}
--
2.43.0
On Fri, Sep 12, 2025 at 12:42 AM David Lechner <dlechner@baylibre.com> wrote: > > Use guard(mutex) in a couple of functions to allow direct returns. This > simplifies the code a bit and will make later changes easier. From this and the patch it's unclear if cleanup.h was already there or not. If not, this patch misses it, if yes, the commit message should be different. -- With Best Regards, Andy Shevchenko
On 9/11/25 11:39 PM, Andy Shevchenko wrote: > On Fri, Sep 12, 2025 at 12:42 AM David Lechner <dlechner@baylibre.com> wrote: >> >> Use guard(mutex) in a couple of functions to allow direct returns. This >> simplifies the code a bit and will make later changes easier. > > From this and the patch it's unclear if cleanup.h was already there or > not. If not, this patch misses it, if yes, the commit message should > be different. > cleanup.h is already there. I'm not sure what would need to be different in the commit message though.
On Fri, Sep 12, 2025 at 09:19:36AM -0500, David Lechner wrote: > On 9/11/25 11:39 PM, Andy Shevchenko wrote: > > On Fri, Sep 12, 2025 at 12:42 AM David Lechner <dlechner@baylibre.com> wrote: > >> > >> Use guard(mutex) in a couple of functions to allow direct returns. This > >> simplifies the code a bit and will make later changes easier. > > > > From this and the patch it's unclear if cleanup.h was already there or > > not. If not, this patch misses it, if yes, the commit message should > > be different. > > cleanup.h is already there. I'm not sure what would need to be different > in the commit message though. I expect something like "finish converting the driver to use guard()()..." -- With Best Regards, Andy Shevchenko
On 9/12/25 12:15 PM, Andy Shevchenko wrote: > On Fri, Sep 12, 2025 at 09:19:36AM -0500, David Lechner wrote: >> On 9/11/25 11:39 PM, Andy Shevchenko wrote: >>> On Fri, Sep 12, 2025 at 12:42 AM David Lechner <dlechner@baylibre.com> wrote: >>>> >>>> Use guard(mutex) in a couple of functions to allow direct returns. This >>>> simplifies the code a bit and will make later changes easier. >>> >>> From this and the patch it's unclear if cleanup.h was already there or >>> not. If not, this patch misses it, if yes, the commit message should >>> be different. >> >> cleanup.h is already there. I'm not sure what would need to be different >> in the commit message though. > > I expect something like "finish converting the driver to use guard()()..." > cleanup.h was previously included for __free(), so the guard() stuff is all new.
On Fri, Sep 12, 2025 at 12:41:08PM -0500, David Lechner wrote: > On 9/12/25 12:15 PM, Andy Shevchenko wrote: > > On Fri, Sep 12, 2025 at 09:19:36AM -0500, David Lechner wrote: > >> On 9/11/25 11:39 PM, Andy Shevchenko wrote: > >>> On Fri, Sep 12, 2025 at 12:42 AM David Lechner <dlechner@baylibre.com> wrote: > >>>> > >>>> Use guard(mutex) in a couple of functions to allow direct returns. This > >>>> simplifies the code a bit and will make later changes easier. > >>> > >>> From this and the patch it's unclear if cleanup.h was already there or > >>> not. If not, this patch misses it, if yes, the commit message should > >>> be different. > >> > >> cleanup.h is already there. I'm not sure what would need to be different > >> in the commit message though. > > > > I expect something like "finish converting the driver to use guard()()..." > > cleanup.h was previously included for __free(), so the guard() stuff > is all new. Okay, then something like "Cover the lock handling using guard()()..." The point I'm trying to make is that "Use $FOO API/etc" without new header being included either: 1) missing inclusion (proxying); 2) start using of a new API from the library/header that we already use for another API, but without mentioning that. -- With Best Regards, Andy Shevchenko
On Fri, 12 Sep 2025 21:07:58 +0300 Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > On Fri, Sep 12, 2025 at 12:41:08PM -0500, David Lechner wrote: > > On 9/12/25 12:15 PM, Andy Shevchenko wrote: > > > On Fri, Sep 12, 2025 at 09:19:36AM -0500, David Lechner wrote: > > >> On 9/11/25 11:39 PM, Andy Shevchenko wrote: > > >>> On Fri, Sep 12, 2025 at 12:42 AM David Lechner <dlechner@baylibre.com> wrote: > > >>>> > > >>>> Use guard(mutex) in a couple of functions to allow direct returns. This > > >>>> simplifies the code a bit and will make later changes easier. > > >>> > > >>> From this and the patch it's unclear if cleanup.h was already there or > > >>> not. If not, this patch misses it, if yes, the commit message should > > >>> be different. > > >> > > >> cleanup.h is already there. I'm not sure what would need to be different > > >> in the commit message though. > > > > > > I expect something like "finish converting the driver to use guard()()..." > > > > cleanup.h was previously included for __free(), so the guard() stuff > > is all new. > > Okay, then something like "Cover the lock handling using guard()()..." > The point I'm trying to make is that "Use $FOO API/etc" without new header > being included either: > 1) missing inclusion (proxying); > 2) start using of a new API from the library/header that we already use for > another API, but without mentioning that. > I went with the far from subtle solution of adding a line to the commit log that says cleanup.h is already included for prior use of __free() Seemed like that would be enough for Andy's request and so I added his tag (as given to the cover letter). Jonathan
© 2016 - 2025 Red Hat, Inc.