From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Vaibhav Chahar <vaibhav.chahar26@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
linux-iio@vger.kernel.org,
"Marius Cristea" <marius.cristea@microchip.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Joshua Crofts" <crofts@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] iio: adc: palmas_gpadc: Use guard(mutex) to manage locks
Date: Wed, 25 Nov 2026 13:32:24 +0200 [thread overview]
Message-ID: <awbHSDdEyW6FS07l@ashevche-desk.local> (raw)
In-Reply-To: <20261124204054.85634-3-vaibhav.chahar26@gmail.com>
On Wed, Nov 25, 2026 at 02:10:54AM +0530, Vaibhav Chahar wrote:
> Use guard(mutex) instead of manual mutex_lock() and mutex_unlock()
> calls to modernize the driver and simplify error handling paths.
>
> Made a new helper function palmas_gpadc_read_raw_locked() and called
> palmas_gpadc_read_done() after it so it can still run before the mutex
> is unlocked, allowing the goto and labels to be removed safely.
...
> - mutex_lock(&adc->lock);
> + guard(mutex)(&adc->lock);
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> case IIO_CHAN_INFO_PROCESSED:
> - ret = palmas_gpadc_read_prepare(adc, adc_chan);
> - if (ret < 0)
> - goto out;
> -
> - ret = palmas_gpadc_start_conversion(adc, adc_chan);
> - if (ret < 0) {
> - dev_err(adc->dev,
> - "ADC start conversion failed\n");
> - goto out;
> - }
> -
> - if (mask == IIO_CHAN_INFO_PROCESSED)
> - ret = palmas_gpadc_get_calibrated_code(
> - adc, adc_chan, ret);
> -
> - *val = ret;
> -
> - ret = IIO_VAL_INT;
> - goto out;
> + ret = palmas_gpadc_read_raw_locked(adc, adc_chan, val, mask);
> + palmas_gpadc_read_done(adc, adc_chan);
> + return ret;
Hmm... But now this _read_done call makes sense inside the helper.
return palmas_gpadc_read_raw_locked(adc, adc_chan, val, mask);
> }
>
> - mutex_unlock(&adc->lock);
> - return ret;
> -
> -out:
> - palmas_gpadc_read_done(adc, adc_chan);
> - mutex_unlock(&adc->lock);
> -
> return ret;
Are you expect anything than 0 here?
...
> - mutex_lock(&adc->lock);
> + guard(mutex)(&adc->lock);
>
> if (palmas_gpadc_get_event(adc, adc_chan, dir))
> - ret = 1;
> + return 1;
>
> - mutex_unlock(&adc->lock);
> -
> - return ret;
> + return 0;
> }
So, what is the returning value of palmas_gpadc_get_event()? It might be
possible to simplify more, but current approach is good enough.
...
> - mutex_lock(&adc->lock);
> + guard(mutex)(&adc->lock);
> +
> switch (info) {
> case IIO_EV_INFO_VALUE:
> - if (val < 0 || val > 0xFFF) {
> - ret = -EINVAL;
> - goto out_unlock;
> - }
> + if (val < 0 || val > 0xFFF)
> + return -EINVAL;
> if (dir == IIO_EV_DIR_RISING) {
> old = adc->thresholds[adc_chan].high;
> adc->thresholds[adc_chan].high = val;
> @@ -759,20 +743,14 @@ static int palmas_gpadc_write_event_value(struct iio_dev *indio_dev,
> old = adc->thresholds[adc_chan].low;
> adc->thresholds[adc_chan].low = val;
> }
> - ret = 0;
> break;
> default:
> - ret = -EINVAL;
> - goto out_unlock;
> + return -EINVAL;
> }
>
> if (val != old && palmas_gpadc_get_event(adc, adc_chan, dir))
> - ret = palmas_gpadc_reconfigure_event_channels(adc);
> -
> -out_unlock:
> - mutex_unlock(&adc->lock);
> -
> - return ret;
> + return palmas_gpadc_reconfigure_event_channels(adc);
I don't see the full context, but can this be moved inside the switch-case now?
> + return 0;
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-11-25 11:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 20:40 [PATCH v3 0/2] iio: adc: Use guard(mutex) to manage locks Vaibhav Chahar
2026-11-24 20:40 ` [PATCH v3 1/2] iio: adc: mcp3564: Use guard() " Vaibhav Chahar
2026-11-25 11:24 ` Andy Shevchenko
2026-11-24 20:40 ` [PATCH v3 2/2] iio: adc: palmas_gpadc: Use guard(mutex) " Vaibhav Chahar
2026-11-25 11:32 ` Andy Shevchenko [this message]
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=awbHSDdEyW6FS07l@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=crofts@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marius.cristea@microchip.com \
--cc=nuno.sa@analog.com \
--cc=vaibhav.chahar26@gmail.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 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.