aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/sram.c
diff options
context:
space:
mode:
authorVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>2015-06-01 08:29:54 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-06-12 20:03:56 -0400
commitee895ccdf776a676655b1405d493cfcf43d157f0 (patch)
tree49b5cf106db7c116b8e1f7dd3f3eec6795800647 /drivers/misc/sram.c
parent0a3405d35c72535d6a57af3cad29ed14d26cd203 (diff)
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: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/sram.c')
-rw-r--r--drivers/misc/sram.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index eeaaf5fca105..76a23f9b5451 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -90,12 +90,6 @@ static int sram_probe(struct platform_device *pdev)
90 if (!sram) 90 if (!sram)
91 return -ENOMEM; 91 return -ENOMEM;
92 92
93 sram->clk = devm_clk_get(&pdev->dev, NULL);
94 if (IS_ERR(sram->clk))
95 sram->clk = NULL;
96 else
97 clk_prepare_enable(sram->clk);
98
99 sram->pool = devm_gen_pool_create(&pdev->dev, ilog2(SRAM_GRANULARITY), -1); 93 sram->pool = devm_gen_pool_create(&pdev->dev, ilog2(SRAM_GRANULARITY), -1);
100 if (!sram->pool) 94 if (!sram->pool)
101 return -ENOMEM; 95 return -ENOMEM;
@@ -106,10 +100,8 @@ static int sram_probe(struct platform_device *pdev)
106 */ 100 */
107 nblocks = (np) ? of_get_available_child_count(np) + 1 : 1; 101 nblocks = (np) ? of_get_available_child_count(np) + 1 : 1;
108 rblocks = kmalloc((nblocks) * sizeof(*rblocks), GFP_KERNEL); 102 rblocks = kmalloc((nblocks) * sizeof(*rblocks), GFP_KERNEL);
109 if (!rblocks) { 103 if (!rblocks)
110 ret = -ENOMEM; 104 return -ENOMEM;
111 goto err_alloc;
112 }
113 105
114 block = &rblocks[0]; 106 block = &rblocks[0];
115 for_each_available_child_of_node(np, child) { 107 for_each_available_child_of_node(np, child) {
@@ -188,6 +180,12 @@ static int sram_probe(struct platform_device *pdev)
188 180
189 kfree(rblocks); 181 kfree(rblocks);
190 182
183 sram->clk = devm_clk_get(&pdev->dev, NULL);
184 if (IS_ERR(sram->clk))
185 sram->clk = NULL;
186 else
187 clk_prepare_enable(sram->clk);
188
191 platform_set_drvdata(pdev, sram); 189 platform_set_drvdata(pdev, sram);
192 190
193 dev_dbg(&pdev->dev, "SRAM pool: %ld KiB @ 0x%p\n", size / 1024, virt_base); 191 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 194
197err_chunks: 195err_chunks:
198 kfree(rblocks); 196 kfree(rblocks);
199err_alloc: 197
200 if (sram->clk)
201 clk_disable_unprepare(sram->clk);
202 return ret; 198 return ret;
203} 199}
204 200