Skip to contentSkip to conversation

iio: adc: bcm_iproc_adc: Simplify probe error handling

PATCH Superseded [email protected] 5 participants 10 messages Aug 1 – Aug 3

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

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

From: Mohammad Shahid <[email protected]>

Hi,

This series simplifies the probe error handling in bcm_iproc_adc.

Changes in v4:
- Move the redundant iproc_adc_enable() error message removal into the cleanup patch as suggested by Joshua Crofts.

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 | 54 +++++++++++++++------------------
 1 file changed, 24 insertions(+), 30 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 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

Re: [PATCH v4 1/3] iio: adc: bcm_iproc_adc: Remove redundant probe error messages

Quoted 33 lines · On Sat, 1 Aug 2026 14:39:51 +0530 [email protected] wrote:

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 +1 -3
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)
 	}

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

Quoted 10 lines
drivers/iio/adc/bcm_iproc_adc.c +1 -3
 
 	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;

This is good.

Side note - I noticed that you added the email [email protected] to the Cc list, however I don't work at Broadcom - there must've been a mixup when you were Ccing people as I only use the address this meesage is sent from.

Thanks.

Signature · 2 lines
Kind regards,
Joshua Crofts
#3 lore raw

PATCH v4 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 instead of repeatedly referencing '&pdev->dev'.

This simplifies the code and makes subsequent error handling changes less verbose.

No functional change intended.

---
 drivers/iio/adc/bcm_iproc_adc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +9 -8
index 7c2e2770cd61..4acd9c3f089b 100644
@@ -506,9 +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,
+	indio_dev = devm_iio_device_alloc(dev,
 					sizeof(*adc_priv));
 	if (!indio_dev)
 		return -ENOMEM;
@@ -523,14 +524,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");
+		dev_err(dev, "failed to get handle for tsc syscon\n");
 		ret = PTR_ERR(adc_priv->regmap);
 		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,
+		dev_err(dev,
 			"failed getting clock tsc_clk\n");
 		ret = PTR_ERR(adc_priv->adc_clk);
 		return ret;
@@ -543,11 +544,11 @@ 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);
+		dev_err(dev, "failed to write IPROC_REGCTL2 %d\n", ret);
 		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);
@@ -556,7 +557,7 @@ static int iproc_adc_probe(struct platform_device *pdev)
 
 	ret = clk_prepare_enable(adc_priv->adc_clk);
 	if (ret) {
-		dev_err(&pdev->dev,
+		dev_err(dev,
 			"clk_prepare_enable failed %d\n", ret);
 		return ret;
 	}
@@ -573,7 +574,7 @@ static int iproc_adc_probe(struct platform_device *pdev)
 
 	ret = iio_device_register(indio_dev);
 	if (ret) {
-		dev_err(&pdev->dev, "iio_device_register failed:err %d\n", ret);
+		dev_err(dev, "iio_device_register failed:err %d\n", ret);
 		goto err_clk;
 	}
 
Signature · 1 line
2.43.0
reviewer
#4 lore raw

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

Quoted 39 lines · On 8/1/26 4:09 AM, [email protected] wrote:

From: Mohammad Shahid <[email protected]>

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

This simplifies the code and makes subsequent error handling changes less verbose.

No functional change intended.

---
 drivers/iio/adc/bcm_iproc_adc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +3 -2
index 7c2e2770cd61..4acd9c3f089b 100644
@@ -506,9 +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,
+	indio_dev = devm_iio_device_alloc(dev,
 					sizeof(*adc_priv));
 	if (!indio_dev)
 		return -ENOMEM;
@@ -523,14 +524,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");
+		dev_err(dev, "failed to get handle for tsc syscon\n");
 		ret = PTR_ERR(adc_priv->regmap);
 		return ret;

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

Quoted 10 lines
drivers/iio/adc/bcm_iproc_adc.c +2 -2
 	}
 
-	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,
+		dev_err(dev,
 			"failed getting clock tsc_clk\n");
 		ret = PTR_ERR(adc_priv->adc_clk);
 		return ret;

I imagine some, if not all, of these will fit on one line now without going over 80 chars.

#5 lore raw

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

In reply to [email protected]

…

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

Quoted 11 lines

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

drivers/iio/adc/bcm_iproc_adc.c +2 -1
@@ -506,9 +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,
+	indio_dev = devm_iio_device_alloc(dev,
 					sizeof(*adc_priv));

…

Would an other adjustment be a bit nicer?

+ indio_dev = devm_iio_device_alloc(dev, sizeof(*adc_priv));

…

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

Quoted 9 lines
drivers/iio/adc/bcm_iproc_adc.c +1 -1
@@ -523,14 +524,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");
+		dev_err(dev, "failed to get handle for tsc syscon\n");
 		ret = PTR_ERR(adc_priv->regmap);
 		return ret;
 	}

…

Can further source code refinements become helpful here?

Regards,
Markus

#6 lore raw

PATCH v4 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]>

This simplifies the probe error handling by replacing open-coded dev_err() and return sequences while preserving the existing messages.

---
 drivers/iio/adc/bcm_iproc_adc.c | 39 +++++++++++++++------------------
 1 file changed, 18 insertions(+), 21 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +18 -21
index 4acd9c3f089b..5fcd528eb88a 100644
@@ -523,19 +523,16 @@ 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(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(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)
@@ -543,10 +540,10 @@ 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(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,
@@ -556,11 +553,10 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return ret;
 
 	ret = clk_prepare_enable(adc_priv->adc_clk);
-	if (ret) {
-		dev_err(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)
@@ -574,7 +570,8 @@ static int iproc_adc_probe(struct platform_device *pdev)
 
 	ret = iio_device_register(indio_dev);
 	if (ret) {
-		dev_err(dev, "iio_device_register failed:err %d\n", ret);
+		dev_err_probe(dev, ret,
+			      "failed to register IIO device\n");
 		goto err_clk;
 	}
 
Signature · 1 line
2.43.0
reviewer
#7 lore raw

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

Quoted 17 lines · On 8/1/26 4:09 AM, [email protected] wrote:

From: Mohammad Shahid <[email protected]>

This simplifies the probe error handling by replacing open-coded dev_err() and return sequences while preserving the existing messages.

---
 drivers/iio/adc/bcm_iproc_adc.c | 39 +++++++++++++++------------------
 1 file changed, 18 insertions(+), 21 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +0 -0
index 4acd9c3f089b..5fcd528eb88a 100644
@@ -523,19 +523,16 @@ 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 528

Quoted 10 lines
drivers/iio/adc/bcm_iproc_adc.c +3 -5
 	adc_priv->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
 			   "adc-syscon");
-	if (IS_ERR(adc_priv->regmap)) {
-		dev_err(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),

Probably fine to put this on the same line as dev since it won't be any longer than the text below.

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

Quoted 12 lines
drivers/iio/adc/bcm_iproc_adc.c +4 -6
+				     "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(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),

same

Quoted 5 lines
drivers/iio/adc/bcm_iproc_adc.c +1 -0
+				     "failed getting clock tsc_clk\n");
 
 	adc_priv->irqno = platform_get_irq(pdev, 0);
 	if (adc_priv->irqno < 0)

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

Quoted 10 lines
drivers/iio/adc/bcm_iproc_adc.c +3 -4
@@ -543,10 +540,10 @@ 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(dev, "failed to write IPROC_REGCTL2 %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev,
+				     ret,

dev and ret should be on the same line.

Quoted 6 lines
drivers/iio/adc/bcm_iproc_adc.c +1 -0
+				     "failed to write IPROC_REGCTL2\n");
 
 	ret = devm_request_threaded_irq(dev, adc_priv->irqno,
 				iproc_adc_interrupt_handler,
@@ -556,11 +553,10 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return ret;

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

Quoted 10 lines
drivers/iio/adc/bcm_iproc_adc.c +3 -5
 
 	ret = clk_prepare_enable(adc_priv->adc_clk);
-	if (ret) {
-		dev_err(dev,
-			"clk_prepare_enable failed %d\n", ret);
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev,
+				     ret,

same

Quoted 14 lines
drivers/iio/adc/bcm_iproc_adc.c +3 -1
+				     "failed to enable clock\n");
 
 	ret = iproc_adc_enable(indio_dev);
 	if (ret)
@@ -574,7 +570,8 @@ static int iproc_adc_probe(struct platform_device *pdev)
 
 	ret = iio_device_register(indio_dev);
 	if (ret) {
-		dev_err(dev, "iio_device_register failed:err %d\n", ret);
+		dev_err_probe(dev, ret,
+			      "failed to register IIO device\n");
 		goto err_clk;
 	}
 
#8 lore raw

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

In reply to [email protected]
Quoted 3 lines

This simplifies the probe error handling by replacing open-coded dev_err() and return sequences while preserving the existing messages.

See also once more:
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.2-rc6#n94

* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.2-rc6#n669

Regards,
Markus

maintainer
#9 lore raw
In reply to [email protected]
Quoted 5 lines · On Sat, 1 Aug 2026 14:39:50 +0530 [email protected] wrote:

From: Mohammad Shahid <[email protected]>

Hi,

This series simplifies the probe error handling in bcm_iproc_adc.

Hi Mohammad

See comments on v3 + slow down. It wastes your time and that of reviewers if you post new versions too quickly.

Jonathan

Quoted 14 lines

Changes in v4:
- Move the redundant iproc_adc_enable() error message removal into the cleanup patch as suggested by Joshua Crofts.

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 | 54 +++++++++++++++------------------
 1 file changed, 24 insertions(+), 30 deletions(-)