OSDN Git Service

spi: jcore: disable ref_clk after getting its rate
authorAlexey Khoroshilov <khoroshilov@ispras.ru>
Sat, 17 Mar 2018 10:05:44 +0000 (13:05 +0300)
committerMark Brown <broonie@kernel.org>
Mon, 19 Mar 2018 00:57:42 +0000 (17:57 -0700)
The driver does not disable ref_clk on remove.
According to the comment, the only reason to enable the clock is to get
its rate. So, it should be safe to disable clk just after that.

By the way, clk_prepare_enable() looks to be more appropriate
than clk_enable() here.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-jcore.c

index dafed62..702fe57 100644 (file)
@@ -184,10 +184,11 @@ static int jcore_spi_probe(struct platform_device *pdev)
         */
        clock_freq = 50000000;
        clk = devm_clk_get(&pdev->dev, "ref_clk");
-       if (!IS_ERR_OR_NULL(clk)) {
-               if (clk_enable(clk) == 0)
+       if (!IS_ERR(clk)) {
+               if (clk_prepare_enable(clk) == 0) {
                        clock_freq = clk_get_rate(clk);
-               else
+                       clk_disable_unprepare(clk);
+               } else
                        dev_warn(&pdev->dev, "could not enable ref_clk\n");
        }
        hw->clock_freq = clock_freq;
@@ -198,10 +199,8 @@ static int jcore_spi_probe(struct platform_device *pdev)
 
        /* Register our spi controller */
        err = devm_spi_register_master(&pdev->dev, master);
-       if (err) {
-               clk_disable(clk);
+       if (err)
                goto exit;
-       }
 
        return 0;