Skip to contentSkip to conversation

iio: frequency: use dev_err_probe for admv4420 and ad9523

PATCH Superseded Antoniu Miclaus 3 participants 11 messages Mar 6 – Mar 7

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover iio: frequency: use dev_err_probe for admv4420 and ad9523

Use dev_err_probe() instead of dev_err() in the probe paths of the admv4420 and ad9523 frequency drivers.

Each driver update is split into two patches:
- First patch introduces a local struct device variable in the probe function and replaces &spi->dev references in non-error paths.
- Second patch converts dev_err() calls to dev_err_probe() in the probe path.

No lines are edited twice across patch pairs.

Antoniu Miclaus (4):
iio: frequency: admv4420: add dev variable
iio: frequency: admv4420: use dev_err_probe
iio: frequency: ad9523: add dev variable
iio: frequency: ad9523: use dev_err_probe

 drivers/iio/frequency/ad9523.c   | 21 ++++++++++----------
 drivers/iio/frequency/admv4420.c | 34 ++++++++++++++------------------
 2 files changed, 25 insertions(+), 30 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/4 iio: frequency: admv4420: add dev variable

Introduce a local struct device variable in admv4420_probe() to simplify subsequent conversions and improve code readability.

No functional change.

---
 drivers/iio/frequency/admv4420.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iio/frequency/admv4420.c +4 -3
index 8748d9747639..6ebfe08fc211 100644
@@ -344,18 +344,19 @@ static int admv4420_setup(struct iio_dev *indio_dev)
 
 static int admv4420_probe(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
 	struct iio_dev *indio_dev;
 	struct admv4420_state *st;
 	struct regmap *regmap;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (!indio_dev)
 		return -ENOMEM;
 
 	regmap = devm_regmap_init_spi(spi, &admv4420_regmap_config);
 	if (IS_ERR(regmap))
-		return dev_err_probe(&spi->dev, PTR_ERR(regmap),
+		return dev_err_probe(dev, PTR_ERR(regmap),
 				     "Failed to initializing spi regmap\n");
 
 	st = iio_priv(indio_dev);
@@ -373,7 +374,7 @@ static int admv4420_probe(struct spi_device *spi)
 		return ret;
 	}
 
-	return devm_iio_device_register(&spi->dev, indio_dev);
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static const struct of_device_id admv4420_of_match[] = {
Signature · 1 line
2.43.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] iio: frequency: admv4420: add dev variable

Quoted 4 lines · Antoniu Miclaus

Introduce a local struct device variable in admv4420_probe() to simplify subsequent conversions and improve code readability.

No functional change.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

PATCH 2/4 iio: frequency: admv4420: use dev_err_probe

In reply to Antoniu Miclaus

Use dev_err_probe() instead of dev_err() in the probe path to ensure proper handling of deferred probing and to simplify error handling.

---
 drivers/iio/frequency/admv4420.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)
drivers/iio/frequency/admv4420.c +11 -16
index 6ebfe08fc211..2416fe850ecf 100644
@@ -279,10 +279,9 @@ static int admv4420_setup(struct iio_dev *indio_dev)
 	if (ret)
 		return ret;
 
-	if (val != ADMV4420_SCRATCH_PAD_VAL_1) {
-		dev_err(dev, "Failed ADMV4420 to read/write scratchpad %x ", val);
-		return -EIO;
-	}
+	if (val != ADMV4420_SCRATCH_PAD_VAL_1)
+		return dev_err_probe(dev, -EIO,
+				     "Failed ADMV4420 to read/write scratchpad %x\n", val);
 
 	ret = regmap_write(st->regmap,
 			   ADMV4420_SCRATCHPAD,
@@ -294,10 +293,9 @@ static int admv4420_setup(struct iio_dev *indio_dev)
 	if (ret)
 		return ret;
 
-	if (val != ADMV4420_SCRATCH_PAD_VAL_2) {
-		dev_err(dev, "Failed to read/write scratchpad %x ", val);
-		return -EIO;
-	}
+	if (val != ADMV4420_SCRATCH_PAD_VAL_2)
+		return dev_err_probe(dev, -EIO,
+				     "Failed to read/write scratchpad %x\n", val);
 
 	st->mux_sel = ADMV4420_LOCK_DTCT;
 	st->lo_freq_hz = ADMV4420_DEFAULT_LO_FREQ_HZ;
@@ -305,10 +303,9 @@ static int admv4420_setup(struct iio_dev *indio_dev)
 	admv4420_fw_parse(st);
 
 	ret = admv4420_calc_parameters(st);
-	if (ret) {
-		dev_err(dev, "Failed calc parameters for %lld ", st->vco_freq_hz);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed calc parameters for %lld\n", st->vco_freq_hz);
 
 	ret = regmap_write(st->regmap, ADMV4420_R_DIV_L,
 			   FIELD_GET(0xFF, st->ref_block.divider));
@@ -369,10 +366,8 @@ static int admv4420_probe(struct spi_device *spi)
 	indio_dev->num_channels = ARRAY_SIZE(admv4420_channels);
 
 	ret = admv4420_setup(indio_dev);
-	if (ret) {
-		dev_err(&spi->dev, "Setup ADMV4420 failed (%d)\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Setup ADMV4420 failed\n");
 
 	return devm_iio_device_register(dev, indio_dev);
 }
Signature · 1 line
2.43.0
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] iio: frequency: admv4420: use dev_err_probe

Quoted 2 lines · Antoniu Miclaus

Use dev_err_probe() instead of dev_err() in the probe path to ensure proper handling of deferred probing and to simplify error handling.

After addressing the below.

...

drivers/iio/frequency/admv4420.c static int admv4420_setup(struct iio_dev *indio_dev) · line 308

Quoted 8 lines
drivers/iio/frequency/admv4420.c +3 -4
 	ret = admv4420_calc_parameters(st);
-	if (ret) {
-		dev_err(dev, "Failed calc parameters for %lld ", st->vco_freq_hz);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed calc parameters for %lld\n", st->vco_freq_hz);

Besides too long line, are you sure the lld is the proper specifier? I.o.w. is it really signed long long? (It also adds missing '\n', does it need to be mentioned in the commit message?)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

PATCH 3/4 iio: frequency: ad9523: add dev variable

In reply to Antoniu Miclaus

Introduce a local struct device variable in ad9523_probe() to simplify subsequent conversions and improve code readability.

No functional change.

---
 drivers/iio/frequency/ad9523.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/iio/frequency/ad9523.c +9 -8
index ad32eb66edca..6d15ec648280 100644
@@ -948,17 +948,18 @@ static int ad9523_setup(struct iio_dev *indio_dev)
 
 static int ad9523_probe(struct spi_device *spi)
 {
-	struct ad9523_platform_data *pdata = dev_get_platdata(&spi->dev);
+	struct device *dev = &spi->dev;
+	struct ad9523_platform_data *pdata = dev_get_platdata(dev);
 	struct iio_dev *indio_dev;
 	struct ad9523_state *st;
 	int ret;
 
 	if (!pdata) {
-		dev_err(&spi->dev, "no platform data?\n");
+		dev_err(dev, "no platform data?\n");
 		return -EINVAL;
 	}
 
-	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (indio_dev == NULL)
 		return -ENOMEM;
 
@@ -966,16 +967,16 @@ static int ad9523_probe(struct spi_device *spi)
 
 	mutex_init(&st->lock);
 
-	ret = devm_regulator_get_enable(&spi->dev, "vcc");
+	ret = devm_regulator_get_enable(dev, "vcc");
 	if (ret)
 		return ret;
 
-	st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
+	st->pwrdown_gpio = devm_gpiod_get_optional(dev, "powerdown",
 		GPIOD_OUT_HIGH);
 	if (IS_ERR(st->pwrdown_gpio))
 		return PTR_ERR(st->pwrdown_gpio);
 
-	st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
+	st->reset_gpio = devm_gpiod_get_optional(dev, "reset",
 		GPIOD_OUT_LOW);
 	if (IS_ERR(st->reset_gpio))
 		return PTR_ERR(st->reset_gpio);
@@ -985,7 +986,7 @@ static int ad9523_probe(struct spi_device *spi)
 		gpiod_direction_output(st->reset_gpio, 1);
 	}
 
-	st->sync_gpio = devm_gpiod_get_optional(&spi->dev, "sync",
+	st->sync_gpio = devm_gpiod_get_optional(dev, "sync",
 		GPIOD_OUT_HIGH);
 	if (IS_ERR(st->sync_gpio))
 		return PTR_ERR(st->sync_gpio);
@@ -1005,7 +1006,7 @@ static int ad9523_probe(struct spi_device *spi)
 	if (ret < 0)
 		return ret;
 
-	return devm_iio_device_register(&spi->dev, indio_dev);
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static const struct spi_device_id ad9523_id[] = {
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH 3/4] iio: frequency: ad9523: add dev variable

Quoted 2 lines · Antoniu Miclaus

Introduce a local struct device variable in ad9523_probe() to simplify subsequent conversions and improve code readability.

...

drivers/iio/frequency/ad9523.c static int ad9523_setup(struct iio_dev *indio_dev) · line 952

Quoted 5 lines

static int ad9523_probe(struct spi_device *spi)
{

drivers/iio/frequency/ad9523.c +2 -1
-	struct ad9523_platform_data *pdata = dev_get_platdata(&spi->dev);
+	struct device *dev = &spi->dev;
+	struct ad9523_platform_data *pdata = dev_get_platdata(dev);

It's always better to split assignment and definition when the result is going to be validated. It makes code robust against potential changes in between that might alter that variable / value.

	struct ad9523_platform_data *pdata;

drivers/iio/frequency/ad9523.c static int ad9523_setup(struct iio_dev *indio_dev) · line 955

Quoted 3 lines
drivers/iio/frequency/ad9523.c +0 -0
 	struct iio_dev *indio_dev;
 	struct ad9523_state *st;
 	int ret;
	pdata = dev_get_platdata(dev);

drivers/iio/frequency/ad9523.c static int ad9523_setup(struct iio_dev *indio_dev) · line 958

Quoted 3 lines
drivers/iio/frequency/ad9523.c +1 -1
 	if (!pdata) {
-		dev_err(&spi->dev, "no platform data?\n");
+		dev_err(dev, "no platform data?\n");

This line can be updated in the second patch altogether.

Quoted 2 lines
drivers/iio/frequency/ad9523.c +0 -0
 		return -EINVAL;
 	}

...

drivers/iio/frequency/ad9523.c static int ad9523_probe(struct spi_device *spi) · line 982

Quoted 5 lines
drivers/iio/frequency/ad9523.c +1 -1
-	st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
+	st->reset_gpio = devm_gpiod_get_optional(dev, "reset",
 		GPIOD_OUT_LOW);
 	if (IS_ERR(st->reset_gpio))
 		return PTR_ERR(st->reset_gpio);

Side note: The material to move to reset-gpio driver instead (I think we have tons of the IIO drivers with the same).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

PATCH 4/4 iio: frequency: ad9523: use dev_err_probe

In reply to Antoniu Miclaus

Use dev_err_probe() instead of dev_err() in the probe path to ensure proper handling of deferred probing and to simplify error handling.

---
 drivers/iio/frequency/ad9523.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/frequency/ad9523.c +2 -4
index 6d15ec648280..f29a45837565 100644
@@ -954,10 +954,8 @@ static int ad9523_probe(struct spi_device *spi)
 	struct ad9523_state *st;
 	int ret;
 
-	if (!pdata) {
-		dev_err(dev, "no platform data?\n");
-		return -EINVAL;
-	}
+	if (!pdata)
+		return dev_err_probe(dev, -EINVAL, "no platform data?\n");
 
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (indio_dev == NULL)
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH 4/4] iio: frequency: ad9523: use dev_err_probe

Quoted 2 lines · Antoniu Miclaus

Use dev_err_probe() instead of dev_err() in the probe path to ensure proper handling of deferred probing and to simplify error handling.

...

drivers/iio/frequency/ad9523.c static int ad9523_probe(struct spi_device *spi) · line 958

Quoted 6 lines
drivers/iio/frequency/ad9523.c +2 -4
-	if (!pdata) {
-		dev_err(dev, "no platform data?\n");
-		return -EINVAL;
-	}
+	if (!pdata)
+		return dev_err_probe(dev, -EINVAL, "no platform data?\n");

Platform data?! Maybe we can get rid of it entirely?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#9 lore raw

Re: [PATCH 4/4] iio: frequency: ad9523: use dev_err_probe

Quoted 6 lines · On Fri, 6 Mar 2026 14:24:25 +0200 Andy Shevchenko…
Quoted 2 lines · Antoniu Miclaus

Use dev_err_probe() instead of dev_err() in the probe path to ensure proper handling of deferred probing and to simplify error handling.

...

Quoted 8 lines

drivers/iio/frequency/ad9523.c static int ad9523_probe(struct spi_device *spi) · line 958

Quoted 6 lines
drivers/iio/frequency/ad9523.c +2 -4
-	if (!pdata) {
-		dev_err(dev, "no platform data?\n");
-		return -EINVAL;
-	}
+	if (!pdata)
+		return dev_err_probe(dev, -EINVAL, "no platform data?\n");  

Platform data?! Maybe we can get rid of it entirely?

Good thing to do, but big job. There is no DT binding for this and the platform data is very complex. I checked though and the part is still recommended for new designs so if Analog wants to support it going forward that work needs doing.

Jonathan

Quoted 1 line
#10 lore raw
In reply to Antoniu Miclaus
Quoted 2 lines · Antoniu Miclaus

Use dev_err_probe() instead of dev_err() in the probe paths of the admv4420 and ad9523 frequency drivers.

In the subject you need to use () as well: dev_err_probe().

Signature · 2 lines
With Best Regards,
Andy Shevchenko