Re: [PATCH 4/4] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros

From: Andy Shevchenko

Date: Mon Apr 20 2026 - 14:12:41 EST


On Mon, Apr 20, 2026 at 11:08:04AM +0000, Joshua Crofts wrote:
> The driver currently uses while loops and msleep() for polling during
> conversion waits.
>
> Replace the custom polling loops with readx_poll_timeout() and
> read_poll_timeout() macros from <linux/iopoll.h>. This reduces
> boilerplate, standardizes timeout handling and improves overall code
> readability, keeping the original timing and error behaviour.

...

> /* Wait for the conversion to complete. */
> - while (timeout_ms) {
> - msleep(AK8975_CONVERSION_DONE_POLL_TIME);
> - if (gpiod_get_value(data->eoc_gpiod))
> - break;
> - timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
> - }
> - if (!timeout_ms) {
> + ret = readx_poll_timeout(gpiod_get_value, data->eoc_gpiod, val, val != 0,

' != 0' is not needed, but perhaps okay in this case to explicitly hint that
this is used as boolean conditional.

> + AK8975_CONVERSION_DONE_POLL_TIME * 1000,
> + AK8975_MAX_CONVERSION_TIMEOUT * 1000);

Somebody broke the indentation...

> +

...and added unneeded blank line.

Also, use multipliers from time.h, id est USEC_PER_MSEC.

> + if (ret) {
> dev_err(&client->dev, "Conversion timeout happened\n");
> return -EINVAL;
> }

...

> static int wait_conversion_complete_polled(struct ak8975_data *data)

Same comments as per above.

--
With Best Regards,
Andy Shevchenko