Re: [PATCH v8 2/8] iio: dac: ad5686: missing NULL check on match data
Jonathan Cameron <[email protected]>
| Newsgroups | org.kernel.vger.linux-hardening,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <20260719005533.41520a27@jic23-huawei> |
On Fri, 17 Jul 2026 13:28:52 +0300 Andy Shevchenko <[email protected]> wrote: > On Fri, Jul 17, 2026 at 10:31:26AM +0100, Rodrigo Alencar wrote: > > On 17/07/26 11:15, Andy Shevchenko wrote: > > > On Fri, Jul 17, 2026 at 07:51:35AM +0100, Rodrigo Alencar wrote: > > > > On 16/07/26 21:42, Andy Shevchenko wrote: > > > > > On Thu, Jul 16, 2026 at 01:14:18PM +0100, Rodrigo Alencar via B4 Relay wrote: > > ... > > > > > > > struct iio_dev *indio_dev; > > > > > > int ret, i; > > > > > > > > > > Move an assignment here as well. > > > > > > > > > > chip_info = ... > > > > > > > > assignment? this is an input param validation > > > > > > Can we make sure we always get a correct one to begin with? > > > With that an assignment and check can be coupled together. > > > Also consider use -ENODATA as it's most likely comes from > > > driver_data. > > > > I suppose you are suggesting to move the check to the bus code with: > > > > info = i2c_get_match_data(i2c); > > if (!info) > > return -ENODATA; > > > > rather than here in the core/common code. > > Yes! This avoids layering violation and makes the API contract cleaner. I applied the following rather than going for a v9 for just this: Shout if I messed it up. diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index 8abfaf8f0c46..591596a68004 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -98,8 +98,13 @@ static const struct ad5686_bus_ops ad5686_spi_ops = { static int ad5686_spi_probe(struct spi_device *spi) { - return ad5686_probe(&spi->dev, spi_get_device_match_data(spi), - spi->modalias, &ad5686_spi_ops); + const struct ad5686_chip_info *chip_info; + + chip_info = spi_get_device_match_data(spi); + if (!chip_info) + return -ENODEV; + + return ad5686_probe(&spi->dev, chip_info, spi->modalias, &ad5686_spi_ops); } static const struct spi_device_id ad5686_spi_id[] = { diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c index d49946adbde3..a6c85d0c33c9 100644 --- a/drivers/iio/dac/ad5696-i2c.c +++ b/drivers/iio/dac/ad5696-i2c.c @@ -68,8 +68,13 @@ static const struct ad5686_bus_ops ad5686_i2c_ops = { static int ad5686_i2c_probe(struct i2c_client *i2c) { - return ad5686_probe(&i2c->dev, i2c_get_match_data(i2c), - i2c->name, &ad5686_i2c_ops); + const struct ad5686_chip_info *chip_info; + + chip_info = i2c_get_match_data(i2c); + if (!chip_info) + return -ENODEV; + + return ad5686_probe(&i2c->dev, chip_info, i2c->name, &ad5686_i2c_ops); } > > > > > > > + if (!chip_info) > > > > > > + return -ENODEV; >