]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
PM / devfreq: tegra30: Handle possible round-rate error
authorDmitry Osipenko <digetx@gmail.com>
Mon, 4 Nov 2019 21:56:01 +0000 (00:56 +0300)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 6 Nov 2019 03:04:00 +0000 (12:04 +0900)
The EMC clock rate rounding technically could fail, hence let's handle
the error cases properly.

Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
Tested-by: Peter Geis <pgwipeout@gmail.com>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
drivers/devfreq/tegra30-devfreq.c

index a0a5f3f7b789f1b77ab4291fce456d1f872c1d9d..66dfa98d8c6b278fa92c23ca140ae25ededfdcfe 100644 (file)
@@ -592,8 +592,8 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
        struct tegra_devfreq_device *dev;
        struct tegra_devfreq *tegra;
        struct devfreq *devfreq;
-       unsigned long rate;
        unsigned int i;
+       long rate;
        int err;
 
        tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL);
@@ -650,8 +650,14 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
 
        reset_control_deassert(tegra->reset);
 
-       tegra->max_freq = clk_round_rate(tegra->emc_clock, ULONG_MAX) / KHZ;
+       rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);
+       if (rate < 0) {
+               dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate);
+               return rate;
+       }
+
        tegra->cur_freq = clk_get_rate(tegra->emc_clock) / KHZ;
+       tegra->max_freq = rate / KHZ;
 
        for (i = 0; i < ARRAY_SIZE(actmon_device_configs); i++) {
                dev = tegra->devices + i;
@@ -662,6 +668,13 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
        for (rate = 0; rate <= tegra->max_freq * KHZ; rate++) {
                rate = clk_round_rate(tegra->emc_clock, rate);
 
+               if (rate < 0) {
+                       dev_err(&pdev->dev,
+                               "Failed to round clock rate: %ld\n", rate);
+                       err = rate;
+                       goto remove_opps;
+               }
+
                err = dev_pm_opp_add(&pdev->dev, rate, 0);
                if (err) {
                        dev_err(&pdev->dev, "Failed to add OPP: %d\n", err);