Skip to contentSkip to conversation

ASoC: soc-core: fix an uninitialized use

PATCH In review Jian Cai 2 participants 5 messages Feb 6, 2020 – Feb 7, 2020

Subsystems (2)
lore
Share & tools
lore

Jian Cai

author
#0 lore raw

PATCH 1/1 ASoC: soc-core: fix an uninitialized use

Fixed the uninitialized use of a signed integer variable ret in soc_probe_component when all its definitions are not executed. This caused -ftrivial-auto-var-init=pattern to initialize the variable to repeated 0xAA (i.e. a negative value) and triggered the following code unintentionally.

err_probe:

	if (ret < 0)
		soc_cleanup_component(component);
---
 sound/soc/soc-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/soc-core.c +1 -1
index 068d809c349a..bfb813ba34f3 100644
@@ -1180,7 +1180,7 @@ static int soc_probe_component(struct snd_soc_card *card,
 		snd_soc_component_get_dapm(component);
 	struct snd_soc_dai *dai;
 	int probed = 0;
-	int ret;
+	int ret = 0;
 
 	if (!strcmp(component->name, "snd-soc-dummy"))
 		return 0;
Signature · 1 line
2.25.0.341.g760bfbb309-goog
#1 lore raw
Quoted 7 lines

Fixed the uninitialized use of a signed integer variable ret in soc_probe_component when all its definitions are not executed. This caused -ftrivial-auto-var-init=pattern to initialize the variable to repeated 0xAA (i.e. a negative value) and triggered the following code unintentionally.

Hi Jian,
I don't quite follow; it looks like ret is assigned to multiple times in soc_probe_component. Are one of the return values of one of the functions that are called then assigned to ret undefined? What control flow path leaves ret unitialized?

#3 lore raw
In reply to Jian Cai
Quoted 4 lines · Jian Cai

Hi Nick,

'ret' is only defined in if branches and for loops (e.g. for_each_component_dais). If none of these branches or loops get executed, then eventually we end up having

https://elixir.bootlin.com/linux/latest/source/sound/soc/soc-core.c#L1276
and
https://elixir.bootlin.com/linux/latest/source/sound/soc/soc-core.c#L1287
both assign to ret before any goto is taken. Are you perhaps looking at an older branch of the LTS tree, but not the master branch of the mainline tree? (Or it's possible that it's 1am here in Zurich, and I should go to bed).

Quoted 35 lines

int ret;

err_probe:

        if (ret < 0)
                soc_cleanup_component(component);

With -ftrivial-auto-var-init=pattern, this code becomes

int ret;

err_probe:

       ret = 0xAAAAAAAA;
        if (ret < 0)
                soc_cleanup_component(component);

So soc_cleanup_component gets called unintentionally this case, which causes the built kernel to miss some files.

Quoted 14 lines · Nick Desaulniers
Quoted 8 lines

Fixed the uninitialized use of a signed integer variable ret in soc_probe_component when all its definitions are not executed. This caused -ftrivial-auto-var-init=pattern to initialize the variable to repeated 0xAA (i.e. a negative value) and triggered the following code unintentionally.

Hi Jian,
I don't quite follow; it looks like ret is assigned to multiple times in soc_probe_component. Are one of the return values of one of the functions that are called then assigned to ret undefined? What control flow path leaves ret unitialized?

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#2 lore raw
In reply to Nick Desaulniers

Hi Nick,

'ret' is only defined in if branches and for loops (e.g. for_each_component_dais). If none of these branches or loops get executed, then eventually we end up having

int ret;

err_probe:

        if (ret < 0)
                soc_cleanup_component(component);

With -ftrivial-auto-var-init=pattern, this code becomes

int ret;

err_probe:

       ret = 0xAAAAAAAA;
        if (ret < 0)
                soc_cleanup_component(component);

So soc_cleanup_component gets called unintentionally this case, which causes the built kernel to miss some files.

Quoted 6 lines · Nick Desaulniers
Quoted 5 lines

Fixed the uninitialized use of a signed integer variable ret in soc_probe_component when all its definitions are not executed. This caused -ftrivial-auto-var-init=pattern to initialize the variable to repeated 0xAA (i.e. a negative value) and triggered the following code unintentionally.

Quoted 9 lines
Quoted 1 line

Hi Jian,
I don't quite follow; it looks like ret is assigned to multiple times in soc_probe_component. Are one of the return values of one of the functions that are called then assigned to ret undefined? What control flow path leaves
ret unitialized?

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

author
#4 lore raw
In reply to Nick Desaulniers

Thanks for the pointers. You are absolutely right (despite working late), this is not an issue upstream anymore. I was looking at 4.14 and 4.19 on ChromeOS. I did double check the upstream code but stopped right after seeing 'ret' was still uninitialized. Thanks again for the information.

Quoted 55 lines · Nick Desaulniers
Quoted 4 lines · Jian Cai

Hi Nick,

'ret' is only defined in if branches and for loops (e.g.

for_each_component_dais). If none of these branches or loops get executed, then eventually we end up having

https://elixir.bootlin.com/linux/latest/source/sound/soc/soc-core.c#L1276
and
https://elixir.bootlin.com/linux/latest/source/sound/soc/soc-core.c#L1287
both assign to ret before any goto is taken. Are you perhaps looking at an older branch of the LTS tree, but not the master branch of the mainline tree? (Or it's possible that it's 1am here in Zurich, and I should go to bed).

Quoted 9 lines

int ret;

err_probe:

        if (ret < 0)
                soc_cleanup_component(component);

With -ftrivial-auto-var-init=pattern, this code becomes

Quoted 8 lines

int ret;

err_probe:

       ret = 0xAAAAAAAA;
        if (ret < 0)
                soc_cleanup_component(component);

So soc_cleanup_component gets called unintentionally this case, which

causes the built kernel to miss some files.

Quoted 4 lines

On Thu, Feb 6, 2020 at 3:28 PM Nick Desaulniers <[email protected]>

Quoted 11 lines · wrote:
Quoted 11 lines
Quoted 8 lines

Fixed the uninitialized use of a signed integer variable ret in soc_probe_component when all its definitions are not executed. This caused -ftrivial-auto-var-init=pattern to initialize the variable to repeated 0xAA (i.e. a negative value) and triggered the following code unintentionally.

Hi Jian,
I don't quite follow; it looks like ret is assigned to multiple times

in

Quoted 1 line
Quoted 1 line

soc_probe_component. Are one of the return values of one of the

functions

Quoted 1 line
Quoted 1 line

that are called then assigned to ret undefined? What control flow

Quoted 9 lines

path leaves

Quoted 1 line
Quoted 1 line

ret unitialized?

--
Thanks,
~Nick Desaulniers

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel