Re: [PATCH] iio: magnetometer: ak8975: ensure device is awake for buffered capture
From: Andy Shevchenko
Date: Wed May 13 2026 - 16:41:02 EST
On Wed, May 13, 2026 at 04:35:52PM +0200, Joshua Crofts via B4 Relay wrote:
> Currently, the ak8975_start_read_axis() can be called while the device
> is autosuspended, causing two issues:
>
> 1. I2C transfers in the aforementioned function will fail or timeout
> because ak8975_runtime_suspend() disables the device regulators.
> 2. Since ak8975_fill_buffer() does not hold runtime references,
> ak8975_runtime_suspend() can run concurrently, and since PM callbacks
> do not use a locking mechanism, it may cause a race accessing the
> control register via the I2C bus.
>
> Fix this issue by adding struct iio_buffer_setup_ops that contains
> preenable and postdisable functions to ensure correct that device is
> powered on when running a buffered capture.
I think Suggested-by: Jonathan is appropriate here.
...
> +static int ak8975_buffer_preenable(struct iio_dev *indio_dev)
> +{
> + struct ak8975_data *data = iio_priv(indio_dev);
> + struct device *dev = &data->client->dev;
Not sure if actually may use indio_dev->dev.parent here instead of this, but at
least this one is robust against changing parent-child relations).
> + return pm_runtime_resume_and_get(dev);
> +}
--
With Best Regards,
Andy Shevchenko