Re: [PATCH v6 4/4] iio: adc: ad799x: use devm_iio_device_register and drop remove()

From: Andy Shevchenko

Date: Thu Mar 26 2026 - 15:25:56 EST


On Thu, Mar 26, 2026 at 11:35:29PM +0530, Archit Anant wrote:
> Convert the driver to use the device-managed versions of
> iio_device_register(), iio_triggered_buffer_setup(), and mutex_init().
>
> Use devm_add_action_or_reset() to ensure that the VCC and VREF
> regulators are disabled safely and in the correct order during
> driver teardown or probe failure.
>
> Because all resources (buffer, regulators, IRQs, IIO device, mutex)
> are now fully managed by the devm core, the unwinding order is
> guaranteed to be correct (reverse order of allocation). We can now
> safely remove all manual error handling goto labels in ad799x_probe()
> and delete the ad799x_remove() function entirely.
>
> This eliminates boilerplate code and prevents potential resource leaks.

...

> - mutex_init(&st->lock);
> -
> - ret = iio_device_register(indio_dev);
> + ret = devm_mutex_init(dev, &st->lock);

Looking at how far from the start of probe this is done, it's prone to problems.
What we need is to decouple this change and move mutex to be enabled before any
interrupts or other async events may happen.

> if (ret)
> - goto error_cleanup_ring;
> -
> - return 0;
> -
> -error_cleanup_ring:
> - iio_triggered_buffer_cleanup(indio_dev);
> -error_disable_vref:
> - if (st->vref)
> - regulator_disable(st->vref);
> -error_disable_reg:
> - regulator_disable(st->reg);
> -
> - return ret;
> -}


--
With Best Regards,
Andy Shevchenko