All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: soc-core: fix an uninitialized use
@ 2020-02-06 20:03 ` Jian Cai
  0 siblings, 0 replies; 8+ messages in thread
From: Jian Cai @ 2020-02-06 20:03 UTC (permalink / raw)
  Cc: caij2003, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, alsa-devel, linux-kernel

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);

Signed-off-by: Jian Cai <caij2003@gmail.com>
---
 sound/soc/soc-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 068d809c349a..bfb813ba34f3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -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;
-- 
2.25.0.341.g760bfbb309-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [alsa-devel] [PATCH] ASoC: soc-core: fix an uninitialized use
@ 2020-02-06 20:03 ` Jian Cai
  0 siblings, 0 replies; 8+ messages in thread
From: Jian Cai @ 2020-02-06 20:03 UTC (permalink / raw)
  Cc: alsa-devel, Liam Girdwood, linux-kernel, Takashi Iwai,
	Mark Brown, caij2003

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);

Signed-off-by: Jian Cai <caij2003@gmail.com>
---
 sound/soc/soc-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 068d809c349a..bfb813ba34f3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -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;
-- 
2.25.0.341.g760bfbb309-goog

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH] ASoC: soc-core: fix an uninitialized use
  2020-02-06 20:03 ` [alsa-devel] " Jian Cai
@ 2020-02-06 23:28   ` Nick Desaulniers
  -1 siblings, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2020-02-06 23:28 UTC (permalink / raw)
  To: caij2003
  Cc: alsa-devel, broonie, lgirdwood, linux-kernel, perex, tiwai,
	clang-built-linux

> 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.

> Signed-off-by: Jian Cai <caij2003@gmail.com>

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?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: soc-core: fix an uninitialized use
@ 2020-02-06 23:28   ` Nick Desaulniers
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2020-02-06 23:28 UTC (permalink / raw)
  To: caij2003
  Cc: alsa-devel, lgirdwood, linux-kernel, tiwai, clang-built-linux, broonie

> 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.

> Signed-off-by: Jian Cai <caij2003@gmail.com>

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
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: soc-core: fix an uninitialized use
  2020-02-06 23:28   ` [alsa-devel] " Nick Desaulniers
  (?)
@ 2020-02-06 23:55   ` Jian Cai
  2020-02-07  0:04       ` [alsa-devel] " Nick Desaulniers
  -1 siblings, 1 reply; 8+ messages in thread
From: Jian Cai @ 2020-02-06 23:55 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: alsa-devel, Liam Girdwood, linux-kernel, Takashi Iwai,
	clang-built-linux, Mark Brown

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.



On Thu, Feb 6, 2020 at 3:28 PM Nick Desaulniers <ndesaulniers@google.com>
wrote:

> > 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.
>
> > Signed-off-by: Jian Cai <caij2003@gmail.com>
>
> 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
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: soc-core: fix an uninitialized use
  2020-02-06 23:55   ` Jian Cai
@ 2020-02-07  0:04       ` Nick Desaulniers
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2020-02-07  0:04 UTC (permalink / raw)
  To: Jian Cai
  Cc: alsa-devel, Mark Brown, Liam Girdwood, LKML, Jaroslav Kysela,
	Takashi Iwai, clang-built-linux

On Fri, Feb 7, 2020 at 12:55 AM Jian Cai <caij2003@gmail.com> wrote:
>
> 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).


>
> 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.
>
>
>
> On Thu, Feb 6, 2020 at 3:28 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
>>
>> > 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.
>>
>> > Signed-off-by: Jian Cai <caij2003@gmail.com>
>>
>> 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?



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: soc-core: fix an uninitialized use
@ 2020-02-07  0:04       ` Nick Desaulniers
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2020-02-07  0:04 UTC (permalink / raw)
  To: Jian Cai
  Cc: alsa-devel, Liam Girdwood, LKML, Takashi Iwai, clang-built-linux,
	Mark Brown

On Fri, Feb 7, 2020 at 12:55 AM Jian Cai <caij2003@gmail.com> wrote:
>
> 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).


>
> 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.
>
>
>
> On Thu, Feb 6, 2020 at 3:28 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
>>
>> > 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.
>>
>> > Signed-off-by: Jian Cai <caij2003@gmail.com>
>>
>> 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?



-- 
Thanks,
~Nick Desaulniers
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: soc-core: fix an uninitialized use
  2020-02-07  0:04       ` [alsa-devel] " Nick Desaulniers
  (?)
@ 2020-02-07  0:19       ` Jian Cai
  -1 siblings, 0 replies; 8+ messages in thread
From: Jian Cai @ 2020-02-07  0:19 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: alsa-devel, Liam Girdwood, LKML, Takashi Iwai, clang-built-linux,
	Mark Brown

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.

On Thu, Feb 6, 2020 at 4:04 PM Nick Desaulniers <ndesaulniers@google.com>
wrote:

> On Fri, Feb 7, 2020 at 12:55 AM Jian Cai <caij2003@gmail.com> wrote:
> >
> > 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).
>
>
> >
> > 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.
> >
> >
> >
> > On Thu, Feb 6, 2020 at 3:28 PM Nick Desaulniers <ndesaulniers@google.com>
> wrote:
> >>
> >> > 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.
> >>
> >> > Signed-off-by: Jian Cai <caij2003@gmail.com>
> >>
> >> 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?
>
>
>
> --
> Thanks,
> ~Nick Desaulniers
>
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-02-07 13:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06 20:03 [PATCH] ASoC: soc-core: fix an uninitialized use Jian Cai
2020-02-06 20:03 ` [alsa-devel] " Jian Cai
2020-02-06 23:28 ` Nick Desaulniers
2020-02-06 23:28   ` [alsa-devel] " Nick Desaulniers
2020-02-06 23:55   ` Jian Cai
2020-02-07  0:04     ` Nick Desaulniers
2020-02-07  0:04       ` [alsa-devel] " Nick Desaulniers
2020-02-07  0:19       ` Jian Cai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.