Re: [PATCH v5 08/18] iio: magnetometer: ak8975: check if gpiod read was successful

From: Jonathan Cameron

Date: Wed May 06 2026 - 12:49:04 EST


On Wed, 6 May 2026 09:05:39 +0200
Joshua Crofts <joshua.crofts1@xxxxxxxxx> wrote:

> On Wed, 6 May 2026 at 03:09, Maxwell Doose <m32285159@xxxxxxxxx> wrote:
> >
> > On Tue May 5, 2026 at 6:46 AM CDT, Joshua Crofts via B4 Relay wrote:
> > > From: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
> > >
> > > Add a check that ensures that valid data has been read from GPIOD. If
> > > not, log an error and return the negative read value.
> > >
> > > Suggested-by: Jonathan Cameron <jic23@xxxxxxxxxx>
> > > Signed-off-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
> > > ---
> > > drivers/iio/magnetometer/ak8975.c | 4 ++++
> > > 1 file changed, 4 insertions(+)
> > >
> > > diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> > > index 129c98c97071b4cf8efa3abf2364a3abbde129ba..b3caf5f3ebf29bf701bb214aa480fa7afb2651c6 100644
> > > --- a/drivers/iio/magnetometer/ak8975.c
> > > +++ b/drivers/iio/magnetometer/ak8975.c
> > > @@ -658,6 +658,10 @@ static int wait_conversion_complete_gpio(struct ak8975_data *data,
> > > timeout_ms * USEC_PER_MSEC);
> > > if (ret)
> > > return ret;
> > > + if (val < 0) {
> > > + dev_err(&client->dev, "Error in reading GPIOD\n");
> > > + return val;
> > > + }
> > >
> > > ret = i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST1]);
> > > if (ret < 0)
> >
> > Small nit but I wonder if we can change:
> >
> > if (val < 0) {
> > dev_err(&client->dev, "Error in reading GPIOD\n");
> > return val;
> > }
> >
> > to something like:
> >
> > if (val < 0)
> > return dev_err_probe(&client->dev, val, "Error in reading GPIOD\n");
>
> Sure, but it would go as a separate patch. Given this series is
> 18 parts long, I'd rather get the existing patches merged and
> work on this in another series. This driver still has a few shortcomings
> that should be ironed out.
>

This doesn't look to only be called from probe.
dev_err_probe() is only meant for stuff that is. Arguably
you could use it elsewhere but then it should have a different name.

Thanks,

Jonathan