Re: [PATCH 05/15] iio: adc: check the result of ad_sd_init()

From: Nuno Sá

Date: Wed Oct 28 2026 - 05:42:21 EST


On Tue, Oct 27, 2026 at 05:19:09PM +0100, Greg Kroah-Hartman wrote:
> From: Josef Bacik <josef@xxxxxxxxxxxxxx>
>
> ad_sd_init() asks for the optional "rdy" GPIO and returns the error if
> that fails, for instance -EPROBE_DEFER. The binding of the AD7780
> describes such a GPIO.
>
> ad7780, ad7791, ad7793 and max11205 ignore the result. The function has
> then returned before it set the driver data of the IIO device, which
> devm_ad_sd_setup_buffer_and_trigger() dereferences a few lines further
> down in these probe functions, and sigma_delta->rdy_gpiod holds an
> ERR_PTR() which ad_sigma_delta_clear_pending_event() takes for a GPIO.
>
> Return the error, as the other users of the library do.
>
> Fixes: a87ef09b1fdf ("iio: adc: ad_sigma_delta: Add support for reading irq status using a GPIO")
> Cc: stable <stable@xxxxxxxxxx>
> Cc: "Nuno Sá" <nuno.sa@xxxxxxxxxx>
> Cc: Michael Hennerich <Michael.Hennerich@xxxxxxxxxx>
> Cc: Renato Lui Geh <renatogeh@xxxxxxxxx>
> Cc: David Lechner <dlechner@xxxxxxxxxxxx>
> Cc: Andy Shevchenko <andy@xxxxxxxxxx>
> Cc: Ramona Bolboaca <ramona.bolboaca@xxxxxxxxxx>
> Cc: "Uwe Kleine-König" <u.kleine-koenig@xxxxxxxxxxxx>
> Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> ---

Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>

> drivers/iio/adc/ad7780.c | 4 +++-
> drivers/iio/adc/ad7791.c | 4 +++-
> drivers/iio/adc/ad7793.c | 4 +++-
> drivers/iio/adc/max11205.c | 4 +++-
> 4 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7780.c b/drivers/iio/adc/ad7780.c
> index 1cfad70320fe..c1428f30241c 100644
> --- a/drivers/iio/adc/ad7780.c
> +++ b/drivers/iio/adc/ad7780.c
> @@ -311,7 +311,9 @@ static int ad7780_probe(struct spi_device *spi)
> st = iio_priv(indio_dev);
> st->gain = 1;
>
> - ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info);
> + ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info);
> + if (ret)
> + return ret;
>
> st->chip_info =
> &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data];
> diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
> index c2688307bbba..10aa40ca35e7 100644
> --- a/drivers/iio/adc/ad7791.c
> +++ b/drivers/iio/adc/ad7791.c
> @@ -435,7 +435,9 @@ static int ad7791_probe(struct spi_device *spi)
> return ret;
>
> st->info = &ad7791_chip_infos[spi_get_device_id(spi)->driver_data];
> - ad_sd_init(&st->sd, indio_dev, spi, &ad7791_sigma_delta_info);
> + ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7791_sigma_delta_info);
> + if (ret)
> + return ret;
>
> indio_dev->name = spi_get_device_id(spi)->name;
> indio_dev->modes = INDIO_DIRECT_MODE;
> diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
> index b0f44c144f20..937c8b09ad45 100644
> --- a/drivers/iio/adc/ad7793.c
> +++ b/drivers/iio/adc/ad7793.c
> @@ -796,7 +796,9 @@ static int ad7793_probe(struct spi_device *spi)
>
> st = iio_priv(indio_dev);
>
> - ad_sd_init(&st->sd, indio_dev, spi, &ad7793_sigma_delta_info);
> + ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7793_sigma_delta_info);
> + if (ret)
> + return ret;
>
> if (pdata->refsel != AD7793_REFSEL_INTERNAL) {
> ret = devm_regulator_get_enable_read_voltage(dev, "refin");
> diff --git a/drivers/iio/adc/max11205.c b/drivers/iio/adc/max11205.c
> index 53ac2f4f383e..e46e90400bdc 100644
> --- a/drivers/iio/adc/max11205.c
> +++ b/drivers/iio/adc/max11205.c
> @@ -114,7 +114,9 @@ static int max11205_probe(struct spi_device *spi)
>
> st = iio_priv(indio_dev);
>
> - ad_sd_init(&st->sd, indio_dev, spi, &max11205_sigma_delta_info);
> + ret = ad_sd_init(&st->sd, indio_dev, spi, &max11205_sigma_delta_info);
> + if (ret)
> + return ret;
>
> st->chip_info = spi_get_device_match_data(spi);
> if (!st->chip_info)
>
> --
> 2.56.0
>