Commit ee895ccd authored by Vladimir Zapolskiy's avatar Vladimir Zapolskiy Committed by Greg Kroah-Hartman

misc: sram: fix enabled clock leak on error path

If devm_gen_pool_create() fails, the previously enabled sram->clk is
not disabled on probe() exit.

Because reserved block logic relies only on information from device tree,
there is no need to get and enable device clock in advance, especially
because not provided clock is not considered as an error, so it is
safe to place devm_clk_get() at the end of probe(). No functional
change.
Signed-off-by: default avatarVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0a3405d3
...@@ -90,12 +90,6 @@ static int sram_probe(struct platform_device *pdev) ...@@ -90,12 +90,6 @@ static int sram_probe(struct platform_device *pdev)
if (!sram) if (!sram)
return -ENOMEM; return -ENOMEM;
sram->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(sram->clk))
sram->clk = NULL;
else
clk_prepare_enable(sram->clk);
sram->pool = devm_gen_pool_create(&pdev->dev, ilog2(SRAM_GRANULARITY), -1); sram->pool = devm_gen_pool_create(&pdev->dev, ilog2(SRAM_GRANULARITY), -1);
if (!sram->pool) if (!sram->pool)
return -ENOMEM; return -ENOMEM;
...@@ -106,10 +100,8 @@ static int sram_probe(struct platform_device *pdev) ...@@ -106,10 +100,8 @@ static int sram_probe(struct platform_device *pdev)
*/ */
nblocks = (np) ? of_get_available_child_count(np) + 1 : 1; nblocks = (np) ? of_get_available_child_count(np) + 1 : 1;
rblocks = kmalloc((nblocks) * sizeof(*rblocks), GFP_KERNEL); rblocks = kmalloc((nblocks) * sizeof(*rblocks), GFP_KERNEL);
if (!rblocks) { if (!rblocks)
ret = -ENOMEM; return -ENOMEM;
goto err_alloc;
}
block = &rblocks[0]; block = &rblocks[0];
for_each_available_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
...@@ -188,6 +180,12 @@ static int sram_probe(struct platform_device *pdev) ...@@ -188,6 +180,12 @@ static int sram_probe(struct platform_device *pdev)
kfree(rblocks); kfree(rblocks);
sram->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(sram->clk))
sram->clk = NULL;
else
clk_prepare_enable(sram->clk);
platform_set_drvdata(pdev, sram); platform_set_drvdata(pdev, sram);
dev_dbg(&pdev->dev, "SRAM pool: %ld KiB @ 0x%p\n", size / 1024, virt_base); dev_dbg(&pdev->dev, "SRAM pool: %ld KiB @ 0x%p\n", size / 1024, virt_base);
...@@ -196,9 +194,7 @@ static int sram_probe(struct platform_device *pdev) ...@@ -196,9 +194,7 @@ static int sram_probe(struct platform_device *pdev)
err_chunks: err_chunks:
kfree(rblocks); kfree(rblocks);
err_alloc:
if (sram->clk)
clk_disable_unprepare(sram->clk);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment