Commit 6ee927f2 authored by Amadeusz Sławiński's avatar Amadeusz Sławiński Committed by Mark Brown

ASoC: Intel: Skylake: Fix NULL ptr dereference when unloading clk dev

When driver is probed, we iterate over NHLT and check if clk entries are
present. For each such entry we call register_skl_clk and keep the
result in data->clk[].
Currently data->clk is sparsely indexed using NHLT table iterator, while
when freeing we use number of registered entries. Let's just use
data->avail_clk_cnt as index, so it can be reset back in
unregister_src_clk.
Signed-off-by: default avatarAmadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent e79986ce
...@@ -276,10 +276,8 @@ static void unregister_parent_src_clk(struct skl_clk_parent *pclk, ...@@ -276,10 +276,8 @@ static void unregister_parent_src_clk(struct skl_clk_parent *pclk,
static void unregister_src_clk(struct skl_clk_data *dclk) static void unregister_src_clk(struct skl_clk_data *dclk)
{ {
u8 cnt = dclk->avail_clk_cnt; while (dclk->avail_clk_cnt--)
clkdev_drop(dclk->clk[dclk->avail_clk_cnt]->lookup);
while (cnt--)
clkdev_drop(dclk->clk[cnt]->lookup);
} }
static int skl_register_parent_clks(struct device *dev, static int skl_register_parent_clks(struct device *dev,
...@@ -381,13 +379,13 @@ static int skl_clk_dev_probe(struct platform_device *pdev) ...@@ -381,13 +379,13 @@ static int skl_clk_dev_probe(struct platform_device *pdev)
if (clks[i].rate_cfg[0].rate == 0) if (clks[i].rate_cfg[0].rate == 0)
continue; continue;
data->clk[i] = register_skl_clk(dev, &clks[i], clk_pdata, i); data->clk[data->avail_clk_cnt] = register_skl_clk(dev,
if (IS_ERR(data->clk[i])) { &clks[i], clk_pdata, i);
ret = PTR_ERR(data->clk[i]);
if (IS_ERR(data->clk[data->avail_clk_cnt])) {
ret = PTR_ERR(data->clk[data->avail_clk_cnt++]);
goto err_unreg_skl_clk; goto err_unreg_skl_clk;
} }
data->avail_clk_cnt++;
} }
platform_set_drvdata(pdev, data); platform_set_drvdata(pdev, data);
......
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