Re: [PATCH v2 2/2] iio: adc: palmas_gpadc: Use guard(mutex) to manage locks
From: Andy Shevchenko
Date: Mon Nov 23 2026 - 14:10:08 EST
On Mon, Nov 23, 2026 at 10:58:36PM +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.
>
> In palmas_gpadc_read_raw(), moved palmas_gpadc_read_done() into the exit
> paths inside the switch block so the out: label can be removed while
> preserving hardware teardown before unlocking. In
> palmas_gpadc_write_event_value(), use direct returns instead of jumping
> to out_unlock: label.
A few similar issues as in previous patch, AR: study my review and act
accordingly.
...
> #include <linux/completion.h>
> +#include <linux/cleanup.h>
l is before o.
*yes, I see that the order is a mess.
> #include <linux/of.h>
> #include <linux/iio/events.h>
> #include <linux/iio/iio.h>
...
> ret = palmas_gpadc_read_prepare(adc, adc_chan);
> - if (ret < 0)
> - goto out;
> + if (ret < 0) {
> + palmas_gpadc_read_done(adc, adc_chan);
> + return ret;
> + }
>
> ret = palmas_gpadc_start_conversion(adc, adc_chan);
> if (ret < 0) {
> dev_err(adc->dev,
> "ADC start conversion failed\n");
> - goto out;
> + palmas_gpadc_read_done(adc, adc_chan);
> + return ret;
> }
Nope. In this case split out an inner part into a low-level helper
function and call it _locked() or _unlocked() (I don't remember by
heart what the correct one is in IIO for this case).
...
> default:
> ret = -EINVAL;
> - goto out_unlock;
> + return ret;
So, what's next obvious step?
> }
--
With Best Regards,
Andy Shevchenko