Skip to contentSkip to conversation

PM / devfreq: imx8m-ddrc: convert to use devm_pm_opp_* API

PATCH In review Yangtao Li 2 participants 3 messages Jan 3, 2021 – Jan 5, 2021

Subsystems (9)
lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 28/31 PM / devfreq: imx8m-ddrc: convert to use devm_pm_opp_* API

Use devm_pm_opp_* API to simplify code.

---
 drivers/devfreq/imx8m-ddrc.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/devfreq/imx8m-ddrc.c +2 -13
index bc82d3653bff..9383d6e5538b 100644
@@ -370,11 +370,6 @@ static int imx8m_ddrc_check_opps(struct device *dev)
 	return 0;
 }
 
-static void imx8m_ddrc_exit(struct device *dev)
-{
-	dev_pm_opp_of_remove_table(dev);
-}
-
 static int imx8m_ddrc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -419,7 +414,7 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = dev_pm_opp_of_add_table(dev);
+	ret = devm_pm_opp_of_add_table(dev);
 	if (ret < 0) {
 		dev_err(dev, "failed to get OPP table\n");
 		return ret;
@@ -427,12 +422,11 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
 
 	ret = imx8m_ddrc_check_opps(dev);
 	if (ret < 0)
-		goto err;
+		return ret;
 
 	priv->profile.polling_ms = 1000;
 	priv->profile.target = imx8m_ddrc_target;
 	priv->profile.get_dev_status = imx8m_ddrc_get_dev_status;
-	priv->profile.exit = imx8m_ddrc_exit;
 	priv->profile.get_cur_freq = imx8m_ddrc_get_cur_freq;
 	priv->profile.initial_freq = clk_get_rate(priv->dram_core);
 
@@ -441,13 +435,8 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->devfreq)) {
 		ret = PTR_ERR(priv->devfreq);
 		dev_err(dev, "failed to add devfreq device: %d\n", ret);
-		goto err;
 	}
 
-	return 0;
-
-err:
-	dev_pm_opp_of_remove_table(dev);
 	return ret;
 }
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 49 lines · Yangtao Li

Use devm_pm_opp_* API to simplify code.

---
 drivers/devfreq/imx8m-ddrc.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/devfreq/imx8m-ddrc.c +2 -8
index bc82d3653bff..9383d6e5538b 100644
@@ -370,11 +370,6 @@ static int imx8m_ddrc_check_opps(struct device *dev)
        return 0;
 }
 
-static void imx8m_ddrc_exit(struct device *dev)
-{
-       dev_pm_opp_of_remove_table(dev);
-}
-
 static int imx8m_ddrc_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
@@ -419,7 +414,7 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
                return ret;
        }
 
-       ret = dev_pm_opp_of_add_table(dev);
+       ret = devm_pm_opp_of_add_table(dev);
        if (ret < 0) {
                dev_err(dev, "failed to get OPP table\n");
                return ret;
@@ -427,12 +422,11 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
 
        ret = imx8m_ddrc_check_opps(dev);
        if (ret < 0)
-               goto err;
+               return ret;
 
        priv->profile.polling_ms = 1000;
        priv->profile.target = imx8m_ddrc_target;
        priv->profile.get_dev_status = imx8m_ddrc_get_dev_status;
-       priv->profile.exit = imx8m_ddrc_exit;
        priv->profile.get_cur_freq = imx8m_ddrc_get_cur_freq;
        priv->profile.initial_freq = clk_get_rate(priv->dram_core);
 
@@ -441,13 +435,8 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
        if (IS_ERR(priv->devfreq)) {

drivers/devfreq/imx8m-ddrc.c static int imx8m_ddrc_probe(struct platform_device *pdev) · line 440

Quoted 10 lines
drivers/devfreq/imx8m-ddrc.c +0 -5
                ret = PTR_ERR(priv->devfreq);
                dev_err(dev, "failed to add devfreq device: %d\n", ret);
-               goto err;
        }
 
-       return 0;
-
-err:
-       dev_pm_opp_of_remove_table(dev);
        return ret;

devm_devfreq_add_device() doesn't return any integer value. Even if devm_devfreq_add_device() returns the right devfreq instance, the 'ret' value is not the return value of devm_devfreq_add_device().

On this patch, 'ret' value of 'return ret' is from imx8m_ddrc_check_opps(). Surely, it is well working with this modification. But, it is not code for exception handling.
So, we need to remain the following codes:

    return 0;
err:
    return ret;
Quoted 5 lines
drivers/devfreq/imx8m-ddrc.c +0 -1
 }
 
--

2.25.1

Signature · 6 lines
Best Regards,
Chanwoo Choi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Hi Yangtao,

Quoted 66 lines · Chanwoo Choi
Quoted 49 lines · Yangtao Li

Use devm_pm_opp_* API to simplify code.

---
 drivers/devfreq/imx8m-ddrc.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/devfreq/imx8m-ddrc.c +2 -8
index bc82d3653bff..9383d6e5538b 100644
@@ -370,11 +370,6 @@ static int imx8m_ddrc_check_opps(struct device *dev)
        return 0;
 }
 
-static void imx8m_ddrc_exit(struct device *dev)
-{
-       dev_pm_opp_of_remove_table(dev);
-}
-
 static int imx8m_ddrc_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
@@ -419,7 +414,7 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
                return ret;
        }
 
-       ret = dev_pm_opp_of_add_table(dev);
+       ret = devm_pm_opp_of_add_table(dev);
        if (ret < 0) {
                dev_err(dev, "failed to get OPP table\n");
                return ret;
@@ -427,12 +422,11 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
 
        ret = imx8m_ddrc_check_opps(dev);
        if (ret < 0)
-               goto err;
+               return ret;
 
        priv->profile.polling_ms = 1000;
        priv->profile.target = imx8m_ddrc_target;
        priv->profile.get_dev_status = imx8m_ddrc_get_dev_status;
-       priv->profile.exit = imx8m_ddrc_exit;
        priv->profile.get_cur_freq = imx8m_ddrc_get_cur_freq;
        priv->profile.initial_freq = clk_get_rate(priv->dram_core);
 
@@ -441,13 +435,8 @@ static int imx8m_ddrc_probe(struct platform_device *pdev)
        if (IS_ERR(priv->devfreq)) {

drivers/devfreq/imx8m-ddrc.c static int imx8m_ddrc_probe(struct platform_device *pdev) · line 440

Quoted 10 lines
drivers/devfreq/imx8m-ddrc.c +0 -5
                ret = PTR_ERR(priv->devfreq);
                dev_err(dev, "failed to add devfreq device: %d\n", ret);
-               goto err;
        }
 
-       return 0;
-
-err:
-       dev_pm_opp_of_remove_table(dev);
        return ret;

devm_devfreq_add_device() doesn't return any integer value. Even if devm_devfreq_add_device() returns the right devfreq instance, the 'ret' value is not the return value of devm_devfreq_add_device().

Quoted 9 lines

On this patch, 'ret' value of 'return ret' is from imx8m_ddrc_check_opps(). Surely, it is well working with this modification. But, it is not code for exception handling.
So, we need to remain the following codes:

    return 0;
err:
    return ret;

'err' is not necessary. You better to edit it as following:

if (IS_ERR(priv->devfreq)) {
    dev_err(dev, "failed to add devfreq device: %d\n", ret);
    return PTR_ERR(priv->devfreq);
}

return 0;

Signature · 6 lines
Best Regards,
Chanwoo Choi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel