LKML Archive mirror
 help / color / mirror / Atom feed
* re: ALSA: control - add layer registration routines
@ 2021-03-31 15:17 Colin Ian King
  2021-03-31 18:09 ` Jaroslav Kysela
  0 siblings, 1 reply; 2+ messages in thread
From: Colin Ian King @ 2021-03-31 15:17 UTC (permalink / raw
  To: Jaroslav Kysela
  Cc: Takashi Iwai, Mark Brown, Takashi Sakamoto, alsa-devel,
	linux-kernel@vger.kernel.org

Hi,

Static analysis on linux-next with Coverity has detected a potential
issue in the following commit:

commit 3f0638a0333bfdd0549985aa620f2ab69737af47
Author: Jaroslav Kysela <perex@perex.cz>
Date:   Wed Mar 17 18:29:41 2021 +0100

    ALSA: control - add layer registration routines

The static analysis is as follows:

2072 void snd_ctl_disconnect_layer(struct snd_ctl_layer_ops *lops)
2073 {
2074        struct snd_ctl_layer_ops *lops2, *prev_lops2;
2075
2076        down_write(&snd_ctl_layer_rwsem);

    assignment: Assigning: prev_lops2 = NULL.

2077        for (lops2 = snd_ctl_layer, prev_lops2 = NULL; lops2; lops2
= lops2->next)
2078                if (lops2 == lops) {

    null: At condition prev_lops2, the value of prev_lops2 must be NULL.
    dead_error_condition: The condition !prev_lops2 must be true.

2079                        if (!prev_lops2)
2080                                snd_ctl_layer = lops->next;
2081                        else

    'Constant' variable guards dead code (DEADCODE) dead_error_line:
    Execution cannot reach this statement: prev_lops2->next = lops->next;.
    Local variable prev_lops2 is assigned only once, to a constant
value, making it effectively constant throughout its scope. If this is
not the intent, examine the logic to see if there is a missing
assignment that would make prev_lops2 not remain constant.

2082                                prev_lops2->next = lops->next;
2083                        break;
2084                }
2085        up_write(&snd_ctl_layer_rwsem);
2086 }

I couldn't quite figure out the original intent of the prev_lops use, so
I'd thought I'd report this issue as the code does look incorrect.

Colin

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

* Re: ALSA: control - add layer registration routines
  2021-03-31 15:17 ALSA: control - add layer registration routines Colin Ian King
@ 2021-03-31 18:09 ` Jaroslav Kysela
  0 siblings, 0 replies; 2+ messages in thread
From: Jaroslav Kysela @ 2021-03-31 18:09 UTC (permalink / raw
  To: Colin Ian King
  Cc: Takashi Iwai, Mark Brown, Takashi Sakamoto, alsa-devel,
	linux-kernel@vger.kernel.org

Dne 31. 03. 21 v 17:17 Colin Ian King napsal(a):
> Hi,
> 
> Static analysis on linux-next with Coverity has detected a potential
> issue in the following commit:
> 
> commit 3f0638a0333bfdd0549985aa620f2ab69737af47
> Author: Jaroslav Kysela <perex@perex.cz>
> Date:   Wed Mar 17 18:29:41 2021 +0100
> 
>     ALSA: control - add layer registration routines
> 
> The static analysis is as follows:
> 
> 2072 void snd_ctl_disconnect_layer(struct snd_ctl_layer_ops *lops)
> 2073 {
> 2074        struct snd_ctl_layer_ops *lops2, *prev_lops2;
> 2075
> 2076        down_write(&snd_ctl_layer_rwsem);
> 
>     assignment: Assigning: prev_lops2 = NULL.
> 
> 2077        for (lops2 = snd_ctl_layer, prev_lops2 = NULL; lops2; lops2
> = lops2->next)
> 2078                if (lops2 == lops) {
> 
>     null: At condition prev_lops2, the value of prev_lops2 must be NULL.
>     dead_error_condition: The condition !prev_lops2 must be true.
> 
> 2079                        if (!prev_lops2)
> 2080                                snd_ctl_layer = lops->next;
> 2081                        else
> 
>     'Constant' variable guards dead code (DEADCODE) dead_error_line:
>     Execution cannot reach this statement: prev_lops2->next = lops->next;.
>     Local variable prev_lops2 is assigned only once, to a constant
> value, making it effectively constant throughout its scope. If this is
> not the intent, examine the logic to see if there is a missing
> assignment that would make prev_lops2 not remain constant.
> 
> 2082                                prev_lops2->next = lops->next;
> 2083                        break;
> 2084                }
> 2085        up_write(&snd_ctl_layer_rwsem);
> 2086 }
> 
> I couldn't quite figure out the original intent of the prev_lops use, so
> I'd thought I'd report this issue as the code does look incorrect.

Thank you. I submitted the fix here:

https://lore.kernel.org/alsa-devel/20210331180702.663489-1-perex@perex.cz/

					Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

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

end of thread, other threads:[~2021-03-31 18:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-31 15:17 ALSA: control - add layer registration routines Colin Ian King
2021-03-31 18:09 ` Jaroslav Kysela

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).