[PATCH v1] soc: mediatek: Simplify with dev_err_probe()

Yan Zhen posted 1 patch 2 weeks, 6 days ago
There is a newer version of this series
drivers/soc/mediatek/mtk-mmsys.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
[PATCH v1] soc: mediatek: Simplify with dev_err_probe()
Posted by Yan Zhen 2 weeks, 6 days ago
Using 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. 

Signed-off-by: Yan Zhen <yanzhen@vivo.com>
---
 drivers/soc/mediatek/mtk-mmsys.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/soc/mediatek/mtk-mmsys.c b/drivers/soc/mediatek/mtk-mmsys.c
index 938240714e54..2f2aefd4d830 100644
--- a/drivers/soc/mediatek/mtk-mmsys.c
+++ b/drivers/soc/mediatek/mtk-mmsys.c
@@ -399,8 +399,7 @@ static int mtk_mmsys_probe(struct platform_device *pdev)
 	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;
+		return dev_err_probe(dev, ret, "Failed to ioremap mmsys registers");
 	}
 
 	mmsys->data = of_device_get_match_data(&pdev->dev);
@@ -413,10 +412,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)
+			return dev_err_probe(&pdev->dev, ret,
+						"Couldn't register mmsys reset controller");
 	}
 
 	/* CMDQ is optional */
-- 
2.34.1
Re: [PATCH v1] soc: mediatek: Simplify with dev_err_probe()
Posted by Chen-Yu Tsai 2 weeks, 6 days ago
On Fri, Aug 30, 2024 at 4:28 PM Yan Zhen <yanzhen@vivo.com> wrote:
>
> Using 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.
>
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> ---
>  drivers/soc/mediatek/mtk-mmsys.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/soc/mediatek/mtk-mmsys.c b/drivers/soc/mediatek/mtk-mmsys.c
> index 938240714e54..2f2aefd4d830 100644
> --- a/drivers/soc/mediatek/mtk-mmsys.c
> +++ b/drivers/soc/mediatek/mtk-mmsys.c
> @@ -399,8 +399,7 @@ static int mtk_mmsys_probe(struct platform_device *pdev)
>         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;
> +               return dev_err_probe(dev, ret, "Failed to ioremap mmsys registers");

Nit: I would just get rid of `ret` here.

>         }
>
>         mmsys->data = of_device_get_match_data(&pdev->dev);
> @@ -413,10 +412,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)
> +                       return dev_err_probe(&pdev->dev, ret,
> +                                               "Couldn't register mmsys reset controller");
>         }
>
>         /* CMDQ is optional */
> --
> 2.34.1
>
>