Re: [PATCH v2] staging: iio: adc: ad7816: Use devm_gpiod_get_optional() for busy GPIO

From: Andy Shevchenko

Date: Wed Jun 03 2026 - 05:30:50 EST


On Wed, Jun 03, 2026 at 12:33:33PM +0000, Taha Narimani wrote:
> The driver currently utilizes devm_gpiod_get() for the 'busy' line,
> which makes the GPIO mandatory. However, the busy pin is hardware-optional
> depending on the specific board configuration.
>
> Switch to devm_gpiod_get_optional() to allow boards that do not have
> this pin wired up to still probe the driver successfully, and remove
> the redundant conditional chip-ID check since the optional API handles
> missing descriptors gracefully.

...

> - if (chip->id == ID_AD7817) {
> + if (chip->busy_pin) {

If we get GPIO optional, this check wouldn't be necessary anymore as the below
should return 0 IIRC in this case.

> while (gpiod_get_value(chip->busy_pin))
> cpu_relax();
> }

> + chip->busy_pin = devm_gpiod_get_optional(&spi_dev->dev, "busy",
> + GPIOD_IN);

Make it a single line. Perhaps with a help of

struct device *dev = &spi_dev->dev;

added to the top of the function.

> + if (IS_ERR(chip->busy_pin)) {
> + ret = PTR_ERR(chip->busy_pin);
> + dev_err(&spi_dev->dev, "Failed to request busy GPIO: %d\n",
> + ret);
> + return ret;

You can't do that, it will spam bootlog very quickly if this GPIO is deferred
and never appears. The proper way is to

return dev_err_probe(dev, PTR_ERR(chip->busy_pin), "...");

> }

--
With Best Regards,
Andy Shevchenko