Re: [PATCH] staging: iio: adc: ad7816: add timeout to busy-wait loop

From: Andy Shevchenko

Date: Thu Feb 26 2026 - 03:04:58 EST


On Thu, Feb 26, 2026 at 05:26:15AM +0000, Ruslan Valiyev wrote:
> The ad7816_spi_read() function polls the busy GPIO pin in a tight
> loop without any timeout. If the hardware fails to deassert the
> busy signal, the kernel hangs indefinitely in an unbounded
> busy-wait.
>
> Replace the open-coded while/cpu_relax() loop with
> read_poll_timeout() which polls every 5 us and returns -ETIMEDOUT
> after 1 ms. Per the AD7816 datasheet the maximum conversion time
> is 27 us (temperature channel), so 1 ms provides generous margin.
>
> Also handle the case where gpiod_get_value() returns a negative
> error code, which the original loop silently treated as not-busy.

...

> - while (gpiod_get_value(chip->busy_pin))
> - cpu_relax();
> + int val;
> +
> + ret = read_poll_timeout(gpiod_get_value, val, val <= 0,
> + 5, 1000, false, chip->busy_pin);
> + if (val < 0)
> + return val;
> + if (ret)
> + return ret;

Have you able to test this?

Have you investigated the code? It was an atomic, now it's sleeping.
This is a huge behavioural change. See my first Q.

--
With Best Regards,
Andy Shevchenko