Skip to contentSkip to conversation

iio: adc: ad4030: fix error pointer dereference in probe()

PATCH Applied Dan Carpenter 3 participants 3 messages Feb 28, 2025 – Mar 4, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: ad4030: fix error pointer dereference in probe()

The intention here was obviously to return an error if devm_regmap_init() fails, but the return statement was accidentally left out. This leads to an error pointer dereference when we call:

	ret = ad4030_detect_chip_info(st);

Add the return statement.

Fixes ec25cf6f1ee3 ("iio: adc: ad4030: add support for ad4632-16 and ad4632-24")

---
There is a second Smatch warning which we may want to fix as well:

drivers/iio/adc/ad4030.c:397 ad4030_get_chan_scale()
error: 'scan_type' dereferencing possible ERR_PTR()

There's not error checking on iio_get_current_scan_type().

 drivers/iio/adc/ad4030.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad4030.c +2 -2
index ab5497c8ea1e..b7caf7e89710 100644
@@ -1014,8 +1014,8 @@ static int ad4030_probe(struct spi_device *spi)
 	st->regmap = devm_regmap_init(dev, &ad4030_regmap_bus, st,
 				      &ad4030_regmap_config);
 	if (IS_ERR(st->regmap))
-		dev_err_probe(dev, PTR_ERR(st->regmap),
-			      "Failed to initialize regmap\n");
+		return dev_err_probe(dev, PTR_ERR(st->regmap),
+				     "Failed to initialize regmap\n");
 
 	st->chip = spi_get_device_match_data(spi);
 	if (!st->chip)
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dan Carpenter

The intention here was obviously to return an error if devm_regmap_init() fails, but the return statement was accidentally left out.  This leads to an error pointer dereference when we call:

Quoted 8 lines
	ret = ad4030_detect_chip_info(st);

Add the return statement.

Fixes ec25cf6f1ee3 ("iio: adc: ad4030: add support for ad4632-16 and ad4632-

24")

---

Quoted 25 lines

There is a second Smatch warning which we may want to fix as well:

    drivers/iio/adc/ad4030.c:397 ad4030_get_chan_scale()
    error: 'scan_type' dereferencing possible ERR_PTR()

There's not error checking on iio_get_current_scan_type().

 drivers/iio/adc/ad4030.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad4030.c +2 -2
index ab5497c8ea1e..b7caf7e89710 100644
@@ -1014,8 +1014,8 @@ static int ad4030_probe(struct spi_device *spi)
  	st->regmap = devm_regmap_init(dev, &ad4030_regmap_bus, st,
  				      &ad4030_regmap_config);
  	if (IS_ERR(st->regmap))
-		dev_err_probe(dev, PTR_ERR(st->regmap),
-			      "Failed to initialize regmap\n");
+		return dev_err_probe(dev, PTR_ERR(st->regmap),
+				     "Failed to initialize regmap\n");


  st->chip = spi_get_device_match_data(spi); if (!st->chip)

maintainer Applied
#2 lore raw
Quoted 7 lines · On Fri, 28 Feb 2025 13:22:37 +0000 Nuno Sá <[email protected]> wrote:
Quoted 6 lines · Dan Carpenter

The intention here was obviously to return an error if devm_regmap_init() fails, but the return statement was accidentally left out.  This leads to an error pointer dereference when we call:

	ret = ad4030_detect_chip_info(st);
Quoted 8 lines
Quoted 6 lines

Add the return statement.

Fixes ec25cf6f1ee3 ("iio: adc: ad4030: add support for ad4632-16 and ad4632-

24")

---

Applied.