From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org
Subject: Re: [linux-next:master 9388/11353] sound/soc/soc-compress.c:628 snd_soc_new_compress() error: we previously assumed 'codec_dai' could be null (see line 571)
Date: Wed, 09 Mar 2022 13:18:23 +0300 [thread overview]
Message-ID: <20220309101823.GS3315@kadam> (raw)
In-Reply-To: <20220309093219.1142599-1-jiasheng@iscas.ac.cn>
[-- Attachment #1: Type: text/plain, Size: 1863 bytes --]
On Wed, Mar 09, 2022 at 05:32:19PM +0800, Jiasheng Jiang wrote:
> On Wed, Mar 09, 2022 at 01:58:04AM +0800, Dan Carpenter wrote:
> > smatch warnings:
> > sound/soc/soc-compress.c:628 snd_soc_new_compress() error: we previously assumed 'codec_dai' could be null (see line 571)
>
> > de2c6f98817fa5d Jiasheng Jiang 2021-10-15 @571 if (codec_dai) {
> >
> > Can codec_dai be NULL? This new code assumes so.
>
> > aeb6fa0f15c71a1 Peng Donglin 2017-08-16 @628 rtd->dai_link->stream_name, codec_dai->name, num);
> > ^^^^^^^^^^^^^^^^
> > Unchecked dereference
>
> Actually, if 'codec_dai' is NULL, the check in line 584 will fail and return -EINVAL.
>
> a1068045883ed4a Vinod Koul 2016-01-07 584 if (playback + capture != 1) {
> 141dfc9e3751f5f Charles Keepax 2018-01-26 585 dev_err(rtd->card->dev,
> 141dfc9e3751f5f Charles Keepax 2018-01-26 586 "Compress ASoC: Invalid direction for P %d, C %d\n",
> a1068045883ed4a Vinod Koul 2016-01-07 587 playback, capture);
> a1068045883ed4a Vinod Koul 2016-01-07 588 return -EINVAL;
> a1068045883ed4a Vinod Koul 2016-01-07 589 }
>
Yeah. That's true. Smatch tries to look at conditions and figure out
the implications but this one is too complicated.
But if codec_dai can really be NULL then it would be easier to
understand if we reversed the check on codec_dai and returned early.
if (!codec_dai) {
dev_err(rtd->card->dev, "Missing codec\n");
return -EINVAL;
}
/* check client and interface hw capabilities */
if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK))
playback = 1;
regards,
dan carpenter
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild-all@lists.01.org
Subject: Re: [linux-next:master 9388/11353] sound/soc/soc-compress.c:628 snd_soc_new_compress() error: we previously assumed 'codec_dai' could be null (see line 571)
Date: Wed, 09 Mar 2022 13:18:23 +0300 [thread overview]
Message-ID: <20220309101823.GS3315@kadam> (raw)
In-Reply-To: <20220309093219.1142599-1-jiasheng@iscas.ac.cn>
[-- Attachment #1: Type: text/plain, Size: 1863 bytes --]
On Wed, Mar 09, 2022 at 05:32:19PM +0800, Jiasheng Jiang wrote:
> On Wed, Mar 09, 2022 at 01:58:04AM +0800, Dan Carpenter wrote:
> > smatch warnings:
> > sound/soc/soc-compress.c:628 snd_soc_new_compress() error: we previously assumed 'codec_dai' could be null (see line 571)
>
> > de2c6f98817fa5d Jiasheng Jiang 2021-10-15 @571 if (codec_dai) {
> >
> > Can codec_dai be NULL? This new code assumes so.
>
> > aeb6fa0f15c71a1 Peng Donglin 2017-08-16 @628 rtd->dai_link->stream_name, codec_dai->name, num);
> > ^^^^^^^^^^^^^^^^
> > Unchecked dereference
>
> Actually, if 'codec_dai' is NULL, the check in line 584 will fail and return -EINVAL.
>
> a1068045883ed4a Vinod Koul 2016-01-07 584 if (playback + capture != 1) {
> 141dfc9e3751f5f Charles Keepax 2018-01-26 585 dev_err(rtd->card->dev,
> 141dfc9e3751f5f Charles Keepax 2018-01-26 586 "Compress ASoC: Invalid direction for P %d, C %d\n",
> a1068045883ed4a Vinod Koul 2016-01-07 587 playback, capture);
> a1068045883ed4a Vinod Koul 2016-01-07 588 return -EINVAL;
> a1068045883ed4a Vinod Koul 2016-01-07 589 }
>
Yeah. That's true. Smatch tries to look at conditions and figure out
the implications but this one is too complicated.
But if codec_dai can really be NULL then it would be easier to
understand if we reversed the check on codec_dai and returned early.
if (!codec_dai) {
dev_err(rtd->card->dev, "Missing codec\n");
return -EINVAL;
}
/* check client and interface hw capabilities */
if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK))
playback = 1;
regards,
dan carpenter
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: kbuild@lists.01.org, lkp@intel.com, kbuild-all@lists.01.org,
linux-mm@kvack.org, broonie@kernel.org
Subject: Re: [linux-next:master 9388/11353] sound/soc/soc-compress.c:628 snd_soc_new_compress() error: we previously assumed 'codec_dai' could be null (see line 571)
Date: Wed, 9 Mar 2022 13:18:23 +0300 [thread overview]
Message-ID: <20220309101823.GS3315@kadam> (raw)
In-Reply-To: <20220309093219.1142599-1-jiasheng@iscas.ac.cn>
On Wed, Mar 09, 2022 at 05:32:19PM +0800, Jiasheng Jiang wrote:
> On Wed, Mar 09, 2022 at 01:58:04AM +0800, Dan Carpenter wrote:
> > smatch warnings:
> > sound/soc/soc-compress.c:628 snd_soc_new_compress() error: we previously assumed 'codec_dai' could be null (see line 571)
>
> > de2c6f98817fa5d Jiasheng Jiang 2021-10-15 @571 if (codec_dai) {
> >
> > Can codec_dai be NULL? This new code assumes so.
>
> > aeb6fa0f15c71a1 Peng Donglin 2017-08-16 @628 rtd->dai_link->stream_name, codec_dai->name, num);
> > ^^^^^^^^^^^^^^^^
> > Unchecked dereference
>
> Actually, if 'codec_dai' is NULL, the check in line 584 will fail and return -EINVAL.
>
> a1068045883ed4a Vinod Koul 2016-01-07 584 if (playback + capture != 1) {
> 141dfc9e3751f5f Charles Keepax 2018-01-26 585 dev_err(rtd->card->dev,
> 141dfc9e3751f5f Charles Keepax 2018-01-26 586 "Compress ASoC: Invalid direction for P %d, C %d\n",
> a1068045883ed4a Vinod Koul 2016-01-07 587 playback, capture);
> a1068045883ed4a Vinod Koul 2016-01-07 588 return -EINVAL;
> a1068045883ed4a Vinod Koul 2016-01-07 589 }
>
Yeah. That's true. Smatch tries to look at conditions and figure out
the implications but this one is too complicated.
But if codec_dai can really be NULL then it would be easier to
understand if we reversed the check on codec_dai and returned early.
if (!codec_dai) {
dev_err(rtd->card->dev, "Missing codec\n");
return -EINVAL;
}
/* check client and interface hw capabilities */
if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK))
playback = 1;
regards,
dan carpenter
next prev parent reply other threads:[~2022-03-09 10:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-09 9:32 [linux-next:master 9388/11353] sound/soc/soc-compress.c:628 snd_soc_new_compress() error: we previously assumed 'codec_dai' could be null (see line 571) Jiasheng Jiang
2022-03-09 9:32 ` Jiasheng Jiang
2022-03-09 10:18 ` Dan Carpenter [this message]
2022-03-09 10:18 ` Dan Carpenter
2022-03-09 10:18 ` Dan Carpenter
-- strict thread matches above, loose matches on Subject: below --
2022-03-10 1:38 Jiasheng Jiang
2022-03-10 1:38 ` Jiasheng Jiang
2022-03-08 17:21 kernel test robot
2022-03-08 17:58 ` Dan Carpenter
2022-03-08 17:58 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220309101823.GS3315@kadam \
--to=dan.carpenter@oracle.com \
--cc=kbuild@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.