ASoC: Intel: Skylake: Fix available clock counter incrementation
Subsystems (3)
PATCH 1/1 ASoC: Intel: Skylake: Fix available clock counter incrementation
Incrementation of avail_clk_cnt was incorrectly moved to error path. Put it back to success path.
--- sound/soc/intel/skylake/skl-ssp-clk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/intel/skylake/skl-ssp-clk.c +3 -1
@@ -384,9 +384,11 @@ static int skl_clk_dev_probe(struct platform_device *pdev) &clks[i], clk_pdata, i);if (IS_ERR (data->clk[data->avail_clk_cnt])) { - ret =PTR_ERR (data->clk[data->avail_clk_cnt++]); + ret =PTR_ERR (data->clk[data->avail_clk_cnt]); goto err_unreg_skl_clk; } + + data->avail_clk_cnt++; }platform_set_drvdata (pdev, data);
Signature · 1 line
2.17.1
Quoted 17 lines · Amadeusz Sławiński
Incrementation of
avail_clk_cntwas incorrectly moved to error path. Put it back to success path.Fixes 6ee927f2f01466 ('ASoC: Intel: Skylake: Fix NULL ptr dereference when unloading clk dev')Signed-off-by Amadeusz Sławiński <[email protected]>--- sound/soc/intel/skylake/skl-ssp-clk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)sound/soc/intel/skylake/skl-ssp-clk.c +0
-0@@ -384,9 +384,11 @@ static int skl_clk_dev_probe(struct platform_device *pdev) &clks[i], clk_pdata, i);
sound/soc/intel/skylake/skl-ssp-clk.c static int skl_clk_dev_probe(struct platform_device *pdev) · line 394
Quoted 10 lines
sound/soc/intel/skylake/skl-ssp-clk.c +3
-1if (IS_ERR (data->clk[data->avail_clk_cnt])) { - ret =PTR_ERR (data->clk[data->avail_clk_cnt++]); + ret =PTR_ERR (data->clk[data->avail_clk_cnt]); goto err_unreg_skl_clk; } + + data->avail_clk_cnt++; }platform_set_drvdata (pdev, data);
Thank you for the fix.
Quoted 14 lines · Amadeusz Sławiński
Incrementation of
avail_clk_cntwas incorrectly moved to error path. Put it back to success path.Fixes 6ee927f2f01466 ('ASoC: Intel: Skylake: Fix NULL ptr dereference when unloading clk dev')Signed-off-by Amadeusz Sławiński <[email protected]>--- sound/soc/intel/skylake/skl-ssp-clk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)sound/soc/intel/skylake/skl-ssp-clk.c +0
-0
sound/soc/intel/skylake/skl-ssp-clk.c static int skl_clk_dev_probe(struct platform_device *pdev) · line 387
Quoted 5 lines
sound/soc/intel/skylake/skl-ssp-clk.c +1
-1@@ -384,9 +384,11 @@ static int skl_clk_dev_probe(struct platform_device *pdev) &clks[i], clk_pdata, i);if (IS_ERR (data->clk[data->avail_clk_cnt])) { - ret =PTR_ERR (data->clk[data->avail_clk_cnt++]); + ret =PTR_ERR (data->clk[data->avail_clk_cnt]);
Are you sure?
If you start with avail_clk_cnt set to zero, the error handling will decrement and access offset -1
static void unregister_src_clk(struct skl_clk_data *dclk)
{
while (dclk->avail_clk_cnt--)
clkdev_drop(dclk->clk[dclk->avail_clk_cnt]->lookup); <<< oob access with offset -1
}
Quoted 8 lines
sound/soc/intel/skylake/skl-ssp-clk.c +2
-0goto err_unreg_skl_clk; } + + data->avail_clk_cnt++; }platform_set_drvdata (pdev, data);
Quoted 25 lines · Pierre-Louis Bossart
Quoted 14 lines · Amadeusz Sławiński
Incrementation of
avail_clk_cntwas incorrectly moved to error path. Put it back to success path.Fixes 6ee927f2f01466 ('ASoC: Intel: Skylake: Fix NULL ptr dereference when unloading clk dev')Signed-off-by Amadeusz Sławiński <[email protected]>---
sound/soc/intel/skylake/skl-ssp-clk.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)sound/soc/intel/skylake/skl-ssp-clk.c +0
-0sound/soc/intel/skylake/skl-ssp-clk.c static int skl_clk_dev_probe(struct · line 387
Quoted 5 lines
sound/soc/intel/skylake/skl-ssp-clk.c +1
-1@@ -384,9 +384,11 @@ static int skl_clk_dev_probe(struct platform_device *pdev) &clks[i], clk_pdata, i); if (IS_ERR(data->clk[data->avail_clk_cnt])) { - ret = PTR_ERR(data->clk[data->avail_clk_cnt++]); + ret = PTR_ERR(data->clk[data->avail_clk_cnt]);Are you sure?
Quoted 2 lines
If you start with
avail_clk_cntset to zero, the error handling will decrement and access offset -1
Yes, I'm sure as far as I know c it will first check the value and then decrement it, so it will be 0 while doing the "while" check and it won't enter the loop.
You can double check with simplified usecase:
#include <stdio.h>
int main() {
int i = 0;
while(i--)printf("do something with i, while i = %d\n", i);
}
which seems to work fine to me, by not entering the loop.
Use case is as following:
we start with avail_clk_cnt = 0;
register clock at index 0; increment avail_clk_cnt to 1; register clock at index 1; increment avail_clk_cnt to 2; register clock at index 2; increment avail_clk_cnt to 3
now let's assume that there is no more clocks to register so we do our stuff and then we need to free clocks
so we enter loop
3 evaluates to true, so we decrement it and release clock at index 2 2 evaluates to true, so we decrement it and release clock at index 1 1 evaluates to true, so we decrement it and release clock at index 0 0 evaluates to false, so wo don't enter loop
similar thing happens if we fail to register clock and do error handling
Amadeusz
Cezary Rojewski
maintainerQuoted 18 lines · Pierre-Louis Bossart
Quoted 9 lines · Amadeusz Sławiński
Incrementation of
avail_clk_cntwas incorrectly moved to error path. Put it back to success path.sound/soc/intel/skylake/skl-ssp-clk.c +0
-0sound/soc/intel/skylake/skl-ssp-clk.c static int skl_clk_dev_probe(struct · line 387
Quoted 5 lines
sound/soc/intel/skylake/skl-ssp-clk.c +1
-1@@ -384,9 +384,11 @@ static int skl_clk_dev_probe(struct platform_device *pdev) &clks[i], clk_pdata, i); if (IS_ERR(data->clk[data->avail_clk_cnt])) { - ret = PTR_ERR(data->clk[data->avail_clk_cnt++]); + ret = PTR_ERR(data->clk[data->avail_clk_cnt]);Are you sure?
Quoted 9 lines
If you start with
avail_clk_cntset to zero, the error handling will decrement and access offset -1static void
unregister_src_clk(struct skl_clk_data *dclk)
{
while (dclk->avail_clk_cnt--)clkdev_drop(dclk->clk[dclk->avail_clk_cnt]->lookup); <<< oob
access with offset -1
}
Decrementation will occur after while's check evaluation - loop will exit, decrementation happens regardless.
Pierre-Louis Bossart
Reviewed-byQuoted 21 lines · Cezary Rojewski
Quoted 20 lines · Pierre-Louis Bossart
Quoted 9 lines · Amadeusz Sławiński
Incrementation of
avail_clk_cntwas incorrectly moved to error path. Put it back to success path.sound/soc/intel/skylake/skl-ssp-clk.c +0
-0sound/soc/intel/skylake/skl-ssp-clk.c static int skl_clk_dev_probe(struct · line 387
Quoted 5 lines
sound/soc/intel/skylake/skl-ssp-clk.c +1
-1@@ -384,9 +384,11 @@ static int skl_clk_dev_probe(struct platform_device *pdev) &clks[i], clk_pdata, i); if (IS_ERR(data->clk[data->avail_clk_cnt])) { - ret = PTR_ERR(data->clk[data->avail_clk_cnt++]); + ret = PTR_ERR(data->clk[data->avail_clk_cnt]);Are you sure?
If you start with
avail_clk_cntset to zero, the error handling will decrement and access offset -1
Quoted 8 lines
Quoted 6 lines
static void
unregister_src_clk(struct skl_clk_data *dclk)
{
while (dclk->avail_clk_cnt--)clkdev_drop(dclk->clk[dclk->avail_clk_cnt]->lookup); <<< oob access with offset -1 }Decrementation will occur after while's check evaluation - loop will exit, decrementation happens regardless.
ok, I need more coffee I guess :-)
Mark Brown
maintainerApplied "ASoC: Intel: Skylake: Fix available clock counter incrementation" to the asoc tree
In reply to Amadeusz SławińskiThe patch
ASoC: Intel: Skylake: Fix available clock counter incrementation
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
From 8308a09e87d2cb51adb186dc7d5a5c1913fb0758 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Amadeusz=20S=C5=82awi=C5=84ski?=
<[email protected]>
Date: Mon, 24 Feb 2020 07:52:02 -0500
Subject: [PATCH] ASoC: Intel: Skylake: Fix available clock counter
incrementation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Incrementation of avail_clk_cnt was incorrectly moved to error path. Put it back to success path.
--- sound/soc/intel/skylake/skl-ssp-clk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/intel/skylake/skl-ssp-clk.c +3 -1
@@ -384,9 +384,11 @@ static int skl_clk_dev_probe(struct platform_device *pdev) &clks[i], clk_pdata, i);if (IS_ERR (data->clk[data->avail_clk_cnt])) { - ret =PTR_ERR (data->clk[data->avail_clk_cnt++]); + ret =PTR_ERR (data->clk[data->avail_clk_cnt]); goto err_unreg_skl_clk; } + + data->avail_clk_cnt++; }platform_set_drvdata (pdev, data);
Signature · 1 line
2.20.1