Re: [PATCH v0 04/14] iio: magnetometer: ak8975: Inline timeout constants

Jonathan Cameron
2026-04-28T16:22:22Z

On Mon, 27 Apr 2026 22:09:49 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Since we have switched to using macros from iopoll.h it's better to read
> when the timeout values are explicitly provided in the parameters of the
> respective helpers.
>
> Besides that, fix the home grown and obviously wrong in some cases the
> jiffy-based timeout.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

One comment inline on pulling the actual numbers for the 1st two
close to each other in the driver (or use local constants for them
if you prefer).
> ---
> drivers/iio/magnetometer/ak8975.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index 4cc92a15e937..53987f3b13d2 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -16,6 +16,7 @@
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> #include <linux/iopoll.h>
> +#include <linux/jiffies.h>
> #include <linux/minmax.h>
> #include <linux/mod_devicetable.h>
> #include <linux/module.h>
> @@ -133,13 +134,6 @@
>
> #define AK09912_MAX_REGS AK09912_REG_ASAZ
>
> -/*
> - * Miscellaneous values.
> - */
> -#define AK8975_MAX_CONVERSION_TIMEOUT 500
> -#define AK8975_CONVERSION_DONE_POLL_TIME 10
> -#define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000)
> -
> /*
> * Precalculate scale factor (in Gauss units) for each axis and
> * store in the device data.
> @@ -658,8 +652,7 @@ static int wait_conversion_complete_gpio(struct ak8975_data *data)
>
> /* Wait for the conversion to complete. */
> ret = readx_poll_timeout(gpiod_get_value, data->eoc_gpiod, val, val != 0,
> - AK8975_CONVERSION_DONE_POLL_TIME * USEC_PER_MSEC,
> - AK8975_MAX_CONVERSION_TIMEOUT * USEC_PER_MSEC);
> + 10 * USEC_PER_MSEC, 500 * USEC_PER_MSEC);
> if (ret)
> return ret;
>
> @@ -678,8 +671,7 @@ static int wait_conversion_complete_polled(struct ak8975_data *data)
>
> /* Wait for the conversion to complete. */
> ret = read_poll_timeout(i2c_smbus_read_byte_data, val, val != 0,
> - AK8975_CONVERSION_DONE_POLL_TIME * USEC_PER_MSEC,
> - AK8975_MAX_CONVERSION_TIMEOUT * USEC_PER_MSEC,
> + 10 * USEC_PER_MSEC, 500 * USEC_PER_MSEC,

I'm not that keen on these being repeated in two places given they take the same values.
Perhaps we should push them up to the caller? That is, add them as
parameters of wait_completion_complete_gpio() and wait_completion_polled()

I don't mind if we have them hard coded into those two calls as they are right next
to each other so it should be obvious they values are the same.

Ideally I'd like to see a comment on why these numbers next to those calls.

Fine to pass them in msecs and do the scaling here. Just name the variables to
make that clear. poll_msecs timeout_msecs maybe?

> true,
> client, data->def->ctrl_regs[ST1]);
> if (ret)
> @@ -699,7 +691,7 @@ static int wait_conversion_complete_interrupt(struct ak8975_data *data)
>
> ret = wait_event_timeout(data->data_ready_queue,
> test_bit(0, &data->flags),
> - AK8975_DATA_READY_TIMEOUT);
> + msecs_to_jiffies(100));
> clear_bit(0, &data->flags);
>
> return ret > 0 ? 0 : -ETIMEDOUT;