Skip to contentSkip to conversation

iio: adc: bcm_iproc_adc: Simplify probe error handling

PATCH Superseded [email protected] 3 participants 6 messages Aug 4 – Aug 5

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover iio: adc: bcm_iproc_adc: Simplify probe error handling

From: Mohammad Shahid <[email protected]>

This series simplifies probe error handling in bcm_iproc_adc.

Patch 1 removes redundant probe error messages after devm_request_threaded_irq(), where the helper already reports the error.

Patch 2 introduces a local device pointer to reduce repetition and prepare for subsequent error handling cleanup.

Patch 3 converts immediate-return probe error paths to dev_err_probe() while leaving cleanup paths unchanged.

Changes in v5:
- Keep Patch 2 focused on introducing a local device pointer with minimal code churn.
- Convert only immediate-return probe error paths in Patch 3.
- Leave cleanup (goto) error paths unchanged as suggested during review. Those will be converted separately together with the planned devm-managed cleanup using devm_add_action_or_reset().
- Improve line wrapping and formatting based on review comments.

---
Mohammad Shahid (3):
iio: adc: bcm_iproc_adc: Remove redundant probe error messages
iio: adc: bcm_iproc_adc: Introduce local device pointer
iio: adc: bcm_iproc_adc: Convert probe error handling to

    dev_err_probe()
 drivers/iio/adc/bcm_iproc_adc.c | 48 +++++++++++++--------------------
 1 file changed, 18 insertions(+), 30 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v5 1/3 iio: adc: bcm_iproc_adc: Remove redundant probe error messages

From: Mohammad Shahid <[email protected]>

devm_request_threaded_irq() already logs an error when the request fails, making the explicit dev_err() redundant.

Similarly, iproc_adc_enable() already reports failures, making the additional dev_err() in the probe path redundant.

Remove both duplicate messages.

---
 drivers/iio/adc/bcm_iproc_adc.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +2 -6
index cf4738b16e62..7c2e2770cd61 100644
@@ -551,10 +551,8 @@ static int iproc_adc_probe(struct platform_device *pdev)
 				iproc_adc_interrupt_handler,
 				iproc_adc_interrupt_thread,
 				IRQF_SHARED, "iproc-adc", indio_dev);
-	if (ret) {
-		dev_err(&pdev->dev, "request_irq error %d\n", ret);
+	if (ret)
 		return ret;
-	}
 
 	ret = clk_prepare_enable(adc_priv->adc_clk);
 	if (ret) {
@@ -564,10 +562,8 @@ static int iproc_adc_probe(struct platform_device *pdev)
 	}
 
 	ret = iproc_adc_enable(indio_dev);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to enable adc %d\n", ret);
+	if (ret)
 		goto err_adc_enable;
-	}
 
 	indio_dev->name = "iproc-static-adc";
 	indio_dev->info = &iproc_adc_iio_info;
Signature · 1 line
2.43.0
#2 lore raw

PATCH v5 2/3 iio: adc: bcm_iproc_adc: Introduce local device pointer

In reply to [email protected]

From: Mohammad Shahid <[email protected]>

Introduce a local 'struct device *dev' variable in iproc_adc_probe() and use it for device-managed helper calls instead of repeatedly referencing '&pdev->dev'.

No functional change intended.

---
 drivers/iio/adc/bcm_iproc_adc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +5 -6
index 7c2e2770cd61..312be7c12e58 100644
@@ -506,10 +506,10 @@ static int iproc_adc_probe(struct platform_device *pdev)
 {
 	struct iproc_adc_priv *adc_priv;
 	struct iio_dev *indio_dev = NULL;
+	struct device *dev = &pdev->dev;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&pdev->dev,
-					sizeof(*adc_priv));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*adc_priv));
 	if (!indio_dev)
 		return -ENOMEM;
 
@@ -528,10 +528,9 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	adc_priv->adc_clk = devm_clk_get(&pdev->dev, "tsc_clk");
+	adc_priv->adc_clk = devm_clk_get(dev, "tsc_clk");
 	if (IS_ERR(adc_priv->adc_clk)) {
-		dev_err(&pdev->dev,
-			"failed getting clock tsc_clk\n");
+		dev_err(&pdev->dev, "failed getting clock tsc_clk\n");
 		ret = PTR_ERR(adc_priv->adc_clk);
 		return ret;
 	}
@@ -547,7 +546,7 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = devm_request_threaded_irq(&pdev->dev, adc_priv->irqno,
+	ret = devm_request_threaded_irq(dev, adc_priv->irqno,
 				iproc_adc_interrupt_handler,
 				iproc_adc_interrupt_thread,
 				IRQF_SHARED, "iproc-adc", indio_dev);
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH v5 2/3] iio: adc: bcm_iproc_adc: Introduce local device pointer

Quoted 31 lines · On Tue, 4 Aug 2026 22:35:20 +0530 [email protected] wrote:

From: Mohammad Shahid <[email protected]>

Introduce a local 'struct device *dev' variable in iproc_adc_probe() and use it for device-managed helper calls instead of repeatedly referencing '&pdev->dev'.

No functional change intended.

---
 drivers/iio/adc/bcm_iproc_adc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +2 -2
index 7c2e2770cd61..312be7c12e58 100644
@@ -506,10 +506,10 @@ static int iproc_adc_probe(struct platform_device *pdev)
 {
 	struct iproc_adc_priv *adc_priv;
 	struct iio_dev *indio_dev = NULL;
+	struct device *dev = &pdev->dev;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&pdev->dev,
-					sizeof(*adc_priv));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*adc_priv));
 	if (!indio_dev)
 		return -ENOMEM;
 

drivers/iio/adc/bcm_iproc_adc.c static int iproc_adc_probe(struct platform_device *pdev) · line 533

Quoted 9 lines
drivers/iio/adc/bcm_iproc_adc.c +2 -3
@@ -528,10 +528,9 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	adc_priv->adc_clk = devm_clk_get(&pdev->dev, "tsc_clk");
+	adc_priv->adc_clk = devm_clk_get(dev, "tsc_clk");
 	if (IS_ERR(adc_priv->adc_clk)) {
-		dev_err(&pdev->dev,
-			"failed getting clock tsc_clk\n");
+		dev_err(&pdev->dev, "failed getting clock tsc_clk\n");

Don't do the line rewrap here. It is adding noise we don't want given you are about to replace this line in the next patch.

Quoted 12 lines
drivers/iio/adc/bcm_iproc_adc.c +1 -1
 		ret = PTR_ERR(adc_priv->adc_clk);
 		return ret;
 	}
@@ -547,7 +546,7 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = devm_request_threaded_irq(&pdev->dev, adc_priv->irqno,
+	ret = devm_request_threaded_irq(dev, adc_priv->irqno,
 				iproc_adc_interrupt_handler,
 				iproc_adc_interrupt_thread,
 				IRQF_SHARED, "iproc-adc", indio_dev);
#4 lore raw

PATCH v5 3/3 iio: adc: bcm_iproc_adc: Convert probe error handling to dev_err_probe()

In reply to [email protected]

From: Mohammad Shahid <[email protected]>

Replace open-coded dev_err() followed by return with dev_err_probe() for probe failures that immediately return.

Leave error paths that jump to cleanup labels unchanged to reduce code churn. These paths will be converted separately together with the planned devm-managed cleanup using devm_add_action_or_reset().

---
 drivers/iio/adc/bcm_iproc_adc.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +12 -19
index 312be7c12e58..9238dc8c8873 100644
@@ -522,18 +522,14 @@ static int iproc_adc_probe(struct platform_device *pdev)
 
 	adc_priv->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
 			   "adc-syscon");
-	if (IS_ERR(adc_priv->regmap)) {
-		dev_err(&pdev->dev, "failed to get handle for tsc syscon\n");
-		ret = PTR_ERR(adc_priv->regmap);
-		return ret;
-	}
+	if (IS_ERR(adc_priv->regmap))
+		return dev_err_probe(dev, PTR_ERR(adc_priv->regmap),
+				     "failed to get handle for tsc syscon\n");
 
 	adc_priv->adc_clk = devm_clk_get(dev, "tsc_clk");
-	if (IS_ERR(adc_priv->adc_clk)) {
-		dev_err(&pdev->dev, "failed getting clock tsc_clk\n");
-		ret = PTR_ERR(adc_priv->adc_clk);
-		return ret;
-	}
+	if (IS_ERR(adc_priv->adc_clk))
+		return dev_err_probe(dev, PTR_ERR(adc_priv->adc_clk),
+				     "failed getting clock tsc_clk\n");
 
 	adc_priv->irqno = platform_get_irq(pdev, 0);
 	if (adc_priv->irqno < 0)
@@ -541,10 +537,9 @@ static int iproc_adc_probe(struct platform_device *pdev)
 
 	ret = regmap_clear_bits(adc_priv->regmap, IPROC_REGCTL2,
 				IPROC_ADC_AUXIN_SCAN_ENA);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to write IPROC_REGCTL2 %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to write IPROC_REGCTL2\n");
 
 	ret = devm_request_threaded_irq(dev, adc_priv->irqno,
 				iproc_adc_interrupt_handler,
@@ -554,11 +549,9 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return ret;
 
 	ret = clk_prepare_enable(adc_priv->adc_clk);
-	if (ret) {
-		dev_err(&pdev->dev,
-			"clk_prepare_enable failed %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to enable clock\n");
 
 	ret = iproc_adc_enable(indio_dev);
 	if (ret)
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v5 3/3] iio: adc: bcm_iproc_adc: Convert probe error handling to dev_err_probe()

…

Quoted 2 lines

+++ b/drivers/iio/adc/bcm_iproc_adc.c

(quoted diff) +0 -0
@@ -522,18 +522,14 @@ static int iproc_adc_probe(struct platform_device *pdev)

…

drivers/iio/adc/bcm_iproc_adc.c static int iproc_adc_probe(struct platform_device *pdev) · line 554

Quoted 2 lines
drivers/iio/adc/bcm_iproc_adc.c +2 -0
+		return dev_err_probe(dev, ret,
+				     "failed to enable clock\n");

May indentation be reduced at more source code places?

+ return dev_err_probe(dev, ret, "failed to enable clock\n");

drivers/iio/adc/bcm_iproc_adc.c static int iproc_adc_probe(struct platform_device *pdev) · line 557

Quoted 3 lines
drivers/iio/adc/bcm_iproc_adc.c +0 -0
 	ret = iproc_adc_enable(indio_dev);
 	if (ret)

Regards,
Markus