Re: [PATCH v11 2/6] iio: adc: ad4691: add initial driver for AD4691 family
From: Jonathan Cameron
Date: Sun May 17 2026 - 07:51:21 EST
On Sat, 16 May 2026 12:11:16 -0500
David Lechner <dlechner@xxxxxxxxxxxx> wrote:
> > +static int ad4691_probe(struct spi_device *spi)
> > +{
> > + struct device *dev = &spi->dev;
> > + struct iio_dev *indio_dev;
> > + struct ad4691_state *st;
> > + int ret;
> > +
> > + indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
> > + if (!indio_dev)
> > + return -ENOMEM;
> > +
> > + st = iio_priv(indio_dev);
> > + st->info = spi_get_device_match_data(spi);
> > + if (!st->info)
> > + return -ENODEV;
>
> We've recently standardized on not checking return value
> of spi_get_device_match_data().
There is a wrinkle in that plan. It's still possible to bind these
drivers to a different ID via driver_override and that will land
us in a NULL dereference.
Until we've closed that out (Andy and others are working on it)
we should probably keep these in. Once that's in place we can
cycle back to clean them out + potentially backport that feature
to ensure drivers that are currently not checking are fine.
>
> > +
> > + ret = devm_mutex_init(dev, &st->lock);
> > + if (ret)
> > + return ret;
> > +
> > + st->regmap = devm_regmap_init(dev, NULL, spi, &ad4691_regmap_config);
> > + if (IS_ERR(st->regmap))
> > + return dev_err_probe(dev, PTR_ERR(st->regmap),
> > + "Failed to initialize regmap\n");
> > +
> > + ret = ad4691_regulator_setup(st);
> > + if (ret)
> > + return ret;
> > +
> > + ret = ad4691_reset(st);
> > + if (ret)
> > + return ret;
> > +
> > + ret = ad4691_config(st);
> > + if (ret)
> > + return ret;
> > +
> > + indio_dev->name = st->info->name;
> > + indio_dev->info = &ad4691_info;
> > + indio_dev->modes = INDIO_DIRECT_MODE;
> > +
> > + indio_dev->channels = st->info->sw_info->channels;
> > + indio_dev->num_channels = st->info->sw_info->num_channels;
> > +
> > + return devm_iio_device_register(dev, indio_dev);
> > +}