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

From: Andy Shevchenko

Date: Wed Mar 18 2026 - 10:52:05 EST


On Wed, Mar 18, 2026 at 02:57:15PM +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.

...

> st->vref = devm_regulator_get_optional(dev, "vref");
> ret = PTR_ERR_OR_ZERO(st->vref);
> if (ret) {
> if (ret != -ENODEV)
> - goto error_disable_reg;
> + return ret;
> st->vref = NULL;
> dev_info(dev, "Using VCC reference voltage\n");
> }

if (ret == -ENODEV) {
st->vref = NULL;
dev_info(dev, "Using VCC reference voltage\n");
} else if (ret) {
return ret;
}


--
With Best Regards,
Andy Shevchenko