[media] s5p-fimc: Check return value of clk_enable/clk_set_rate
authorSylwester Nawrocki <s.nawrocki@samsung.com>
Tue, 29 Jan 2013 09:42:28 +0000 (06:42 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 5 Feb 2013 19:50:25 +0000 (17:50 -0200)
clk_set_rate(), clk_enable() functions can fail, so check the return
values to avoid surprises. While at it use ERR_PTR() value to indicate
an invalid clock.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/platform/s5p-fimc/fimc-core.c

index 6d5b03a7b5e517decef8dff8bd5f70d6461c34b0..a9625414ea95a536db8650502b8b5f0d32428241 100644 (file)
@@ -808,11 +808,11 @@ static void fimc_clk_put(struct fimc_dev *fimc)
 {
        int i;
        for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
-               if (IS_ERR_OR_NULL(fimc->clock[i]))
+               if (IS_ERR(fimc->clock[i]))
                        continue;
                clk_unprepare(fimc->clock[i]);
                clk_put(fimc->clock[i]);
-               fimc->clock[i] = NULL;
+               fimc->clock[i] = ERR_PTR(-EINVAL);
        }
 }
 
@@ -820,14 +820,19 @@ static int fimc_clk_get(struct fimc_dev *fimc)
 {
        int i, ret;
 
+       for (i = 0; i < MAX_FIMC_CLOCKS; i++)
+               fimc->clock[i] = ERR_PTR(-EINVAL);
+
        for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
                fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]);
-               if (IS_ERR(fimc->clock[i]))
+               if (IS_ERR(fimc->clock[i])) {
+                       ret = PTR_ERR(fimc->clock[i]);
                        goto err;
+               }
                ret = clk_prepare(fimc->clock[i]);
                if (ret < 0) {
                        clk_put(fimc->clock[i]);
-                       fimc->clock[i] = NULL;
+                       fimc->clock[i] = ERR_PTR(-EINVAL);
                        goto err;
                }
        }
@@ -921,8 +926,14 @@ static int fimc_probe(struct platform_device *pdev)
        ret = fimc_clk_get(fimc);
        if (ret)
                return ret;
-       clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
-       clk_enable(fimc->clock[CLK_BUS]);
+
+       ret = clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
+       if (ret < 0)
+               return ret;
+
+       ret = clk_enable(fimc->clock[CLK_BUS]);
+       if (ret < 0)
+               return ret;
 
        ret = devm_request_irq(&pdev->dev, res->start, fimc_irq_handler,
                               0, dev_name(&pdev->dev), fimc);
@@ -956,6 +967,7 @@ err_pm:
 err_sd:
        fimc_unregister_capture_subdev(fimc);
 err_clk:
+       clk_disable(fimc->clock[CLK_BUS]);
        fimc_clk_put(fimc);
        return ret;
 }