Skip to contentSkip to conversation

soc: mediatek: mtk-mmsys: Simplify with dev_err_probe()

PATCH In review Yan Zhen 2 participants 2 messages Sep 2, 2024 Arm MediaTek

lore
Share & tools
lore

Yan Zhen

author
#0 lore raw

PATCH v3 1/1 soc: mediatek: mtk-mmsys: Simplify with dev_err_probe()

Use dev_err_probe() to simplify the error path and unify a message template.

Using this helper is totally fine even if err is known to never be -EPROBE_DEFER.

The benefit compared to a normal dev_err() is the standardized format of the error code, it being emitted symbolically and the fact that the error code is returned which allows more compact error paths.

---

Changes in v3:
- Modify the message.
- Add the '\n' at the end of the string.

 drivers/soc/mediatek/mtk-mmsys.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/soc/mediatek/mtk-mmsys.c +6 -9
index 938240714e54..170319163c28 100644
@@ -397,11 +397,9 @@ static int mtk_mmsys_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	mmsys->regs = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(mmsys->regs)) {
-		ret = PTR_ERR(mmsys->regs);
-		dev_err(dev, "Failed to ioremap mmsys registers: %d\n", ret);
-		return ret;
-	}
+	if (IS_ERR(mmsys->regs))
+		return dev_err_probe(dev, PTR_ERR(mmsys->regs),
+				     "Failed to ioremap mmsys registers\n");
 
 	mmsys->data = of_device_get_match_data(&pdev->dev);
 
@@ -413,10 +411,9 @@ static int mtk_mmsys_probe(struct platform_device *pdev)
 		mmsys->rcdev.ops = &mtk_mmsys_reset_ops;
 		mmsys->rcdev.of_node = pdev->dev.of_node;
 		ret = devm_reset_controller_register(&pdev->dev, &mmsys->rcdev);
-		if (ret) {
-			dev_err(&pdev->dev, "Couldn't register mmsys reset controller: %d\n", ret);
-			return ret;
-		}
+		if (ret)
+			dev_err_probe(&pdev->dev, ret,
+				      "Couldn't register mmsys reset controller\n");
 	}
 
 	/* CMDQ is optional */
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 40 lines · Yan Zhen

Use dev_err_probe() to simplify the error path and unify a message template.

Using this helper is totally fine even if err is known to never be -EPROBE_DEFER.

The benefit compared to a normal dev_err() is the standardized format of the error code, it being emitted symbolically and the fact that the error code is returned which allows more compact error paths.

---

Changes in v3:
- Modify the message.
- Add the '\n' at the end of the string.

  drivers/soc/mediatek/mtk-mmsys.c | 15 ++++++---------
  1 file changed, 6 insertions(+), 9 deletions(-)
drivers/soc/mediatek/mtk-mmsys.c +3 -5
index 938240714e54..170319163c28 100644
@@ -397,11 +397,9 @@ static int mtk_mmsys_probe(struct platform_device *pdev)
  		return -ENOMEM;
 
  	mmsys->regs = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(mmsys->regs)) {
-		ret = PTR_ERR(mmsys->regs);
-		dev_err(dev, "Failed to ioremap mmsys registers: %d\n", ret);
-		return ret;
-	}
+	if (IS_ERR(mmsys->regs))
+		return dev_err_probe(dev, PTR_ERR(mmsys->regs),
+				     "Failed to ioremap mmsys registers\n");
 
  	mmsys->data = of_device_get_match_data(&pdev->dev);
 

drivers/soc/mediatek/mtk-mmsys.c static int mtk_mmsys_probe(struct platform_device *pdev) · line 416

Quoted 10 lines
drivers/soc/mediatek/mtk-mmsys.c +3 -4
@@ -413,10 +411,9 @@ static int mtk_mmsys_probe(struct platform_device *pdev)
  		mmsys->rcdev.ops = &mtk_mmsys_reset_ops;
  		mmsys->rcdev.of_node = pdev->dev.of_node;
  		ret = devm_reset_controller_register(&pdev->dev, &mmsys->rcdev);
-		if (ret) {
-			dev_err(&pdev->dev, "Couldn't register mmsys reset controller: %d\n", ret);
-			return ret;
-		}
+		if (ret)
+			dev_err_probe(&pdev->dev, ret,
+				      "Couldn't register mmsys reset controller\n");

Your missing return of the error value.

Quoted 3 lines
drivers/soc/mediatek/mtk-mmsys.c +0 -0
  	}
 
  	/* CMDQ is optional */