MLK-11343-01 cpufreq: imx: replace clk_get & regulator_get will devm ones
authorBai Ping <b51503@freescale.com>
Wed, 5 Aug 2015 15:05:46 +0000 (23:05 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 19:47:30 +0000 (14:47 -0500)
Replace the clk_get and regulator_get will the devm ones to free the
resources automatically when probe failed or driver is removed.

Signed-off-by: Bai Ping <b51503@freescale.com>
drivers/cpufreq/imx6q-cpufreq.c

index ef1fa81..a0230c6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Freescale Semiconductor, Inc.
+ * Copyright (C) 2013-2015 Freescale Semiconductor, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -198,16 +198,16 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
                return -ENOENT;
        }
 
-       arm_clk = clk_get(cpu_dev, "arm");
-       pll1_sys_clk = clk_get(cpu_dev, "pll1_sys");
-       pll1_sw_clk = clk_get(cpu_dev, "pll1_sw");
-       step_clk = clk_get(cpu_dev, "step");
-       pll2_pfd2_396m_clk = clk_get(cpu_dev, "pll2_pfd2_396m");
+       arm_clk = devm_clk_get(cpu_dev, "arm");
+       pll1_sys_clk = devm_clk_get(cpu_dev, "pll1_sys");
+       pll1_sw_clk = devm_clk_get(cpu_dev, "pll1_sw");
+       step_clk = devm_clk_get(cpu_dev, "step");
+       pll2_pfd2_396m_clk = devm_clk_get(cpu_dev, "pll2_pfd2_396m");
        if (IS_ERR(arm_clk) || IS_ERR(pll1_sys_clk) || IS_ERR(pll1_sw_clk) ||
            IS_ERR(step_clk) || IS_ERR(pll2_pfd2_396m_clk)) {
                dev_err(cpu_dev, "failed to get clocks\n");
                ret = -ENOENT;
-               goto put_clk;
+               goto put_node;
        }
 
        if (of_machine_is_compatible("fsl,imx6ul")) {
@@ -216,17 +216,17 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
                if (IS_ERR(pll2_bus_clk) || IS_ERR(secondary_sel_clk)) {
                        dev_err(cpu_dev, "failed to get clocks specific to imx6ul\n");
                        ret = -ENOENT;
-                       goto put_clk;
+                       goto put_node;
                }
        }
 
-       arm_reg = regulator_get(cpu_dev, "arm");
-       pu_reg = regulator_get_optional(cpu_dev, "pu");
-       soc_reg = regulator_get(cpu_dev, "soc");
+       arm_reg = devm_regulator_get(cpu_dev, "arm");
+       pu_reg = devm_regulator_get_optional(cpu_dev, "pu");
+       soc_reg = devm_regulator_get(cpu_dev, "soc");
        if (IS_ERR(arm_reg) || IS_ERR(soc_reg)) {
                dev_err(cpu_dev, "failed to get regulators\n");
                ret = -ENOENT;
-               goto put_reg;
+               goto put_node;
        }
 
        /*
@@ -239,7 +239,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
                ret = dev_pm_opp_of_add_table(cpu_dev);
                if (ret < 0) {
                        dev_err(cpu_dev, "failed to init OPP table: %d\n", ret);
-                       goto put_reg;
+                       goto put_node;
                }
 
                /* Because we have added the OPPs here, we must free them */
@@ -256,7 +256,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
        ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
        if (ret) {
                dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
-               goto put_reg;
+               goto out_free_opp;
        }
 
        /* Make imx6_soc_volt array's size same as arm opp number */
@@ -347,28 +347,7 @@ free_freq_table:
 out_free_opp:
        if (free_opp)
                dev_pm_opp_of_remove_table(cpu_dev);
-put_reg:
-       if (!IS_ERR(arm_reg))
-               regulator_put(arm_reg);
-       if (!IS_ERR(pu_reg))
-               regulator_put(pu_reg);
-       if (!IS_ERR(soc_reg))
-               regulator_put(soc_reg);
-put_clk:
-       if (!IS_ERR(arm_clk))
-               clk_put(arm_clk);
-       if (!IS_ERR(pll1_sys_clk))
-               clk_put(pll1_sys_clk);
-       if (!IS_ERR(pll1_sw_clk))
-               clk_put(pll1_sw_clk);
-       if (!IS_ERR(step_clk))
-               clk_put(step_clk);
-       if (!IS_ERR(pll2_pfd2_396m_clk))
-               clk_put(pll2_pfd2_396m_clk);
-       if (!IS_ERR(pll2_bus_clk))
-               clk_put(pll2_bus_clk);
-       if (!IS_ERR(secondary_sel_clk))
-               clk_put(secondary_sel_clk);
+put_node:
        of_node_put(np);
        return ret;
 }
@@ -379,17 +358,6 @@ static int imx6q_cpufreq_remove(struct platform_device *pdev)
        dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
        if (free_opp)
                dev_pm_opp_of_remove_table(cpu_dev);
-       regulator_put(arm_reg);
-       if (!IS_ERR(pu_reg))
-               regulator_put(pu_reg);
-       regulator_put(soc_reg);
-       clk_put(arm_clk);
-       clk_put(pll1_sys_clk);
-       clk_put(pll1_sw_clk);
-       clk_put(step_clk);
-       clk_put(pll2_pfd2_396m_clk);
-       clk_put(pll2_bus_clk);
-       clk_put(secondary_sel_clk);
 
        return 0;
 }