* [PATCH] ASoC: Intel: sof_sdw: initialize ret in asoc_sdw_rt_amp_spk_rtd_init()
@ 2025-02-11 4:08 Ethan Carter Edwards
2025-02-11 13:13 ` Mark Brown
0 siblings, 1 reply; 4+ messages in thread
From: Ethan Carter Edwards @ 2025-02-11 4:08 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, linux-hardening, Ethan Carter Edwards
There is a possibility for an uninitialized *ret* variable to be
returned in some code paths.
Setting to 0 prevents a random value from being returned.
Closes: https://scan5.scan.coverity.com/#/project-view/63873/10063?selectedIssue=1627120
Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
Would it potentially be better to remove ret entirely and just return 0
explicitly at the end of the function and directly return in the if
statements? I'm not sure.
---
sound/soc/sdw_utils/soc_sdw_rt_amp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/sdw_utils/soc_sdw_rt_amp.c b/sound/soc/sdw_utils/soc_sdw_rt_amp.c
index 0538c252ba69b1f5a24ba2de2a610b22d0c0665f..61a00a3548d85689c13e2d2a301da17a572e4a0e 100644
--- a/sound/soc/sdw_utils/soc_sdw_rt_amp.c
+++ b/sound/soc/sdw_utils/soc_sdw_rt_amp.c
@@ -190,7 +190,7 @@ int asoc_sdw_rt_amp_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc
const struct snd_soc_dapm_route *rt_amp_map;
char codec_name[CODEC_NAME_SIZE];
struct snd_soc_dai *codec_dai;
- int ret;
+ int ret = 0;
int i;
rt_amp_map = get_codec_name_and_route(dai, codec_name);
---
base-commit: febbc555cf0fff895546ddb8ba2c9a523692fb55
change-id: 20250210-soc_sdw_rt_amp-e9c703ebe4dc
Best regards,
--
Ethan Carter Edwards <ethan@ethancedwards.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ASoC: Intel: sof_sdw: initialize ret in asoc_sdw_rt_amp_spk_rtd_init()
2025-02-11 4:08 [PATCH] ASoC: Intel: sof_sdw: initialize ret in asoc_sdw_rt_amp_spk_rtd_init() Ethan Carter Edwards
@ 2025-02-11 13:13 ` Mark Brown
2025-02-11 18:54 ` Pierre-Louis Bossart
0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2025-02-11 13:13 UTC (permalink / raw)
To: Ethan Carter Edwards
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-kernel, linux-hardening
[-- Attachment #1: Type: text/plain, Size: 446 bytes --]
On Mon, Feb 10, 2025 at 11:08:27PM -0500, Ethan Carter Edwards wrote:
> There is a possibility for an uninitialized *ret* variable to be
> returned in some code paths.
>
> Setting to 0 prevents a random value from being returned.
That'll shut up the warning but is the warning trying to tell us that
there's a logic bug somewhere in the function and we're for example
forgetting to look at a return value in some path in the function?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ASoC: Intel: sof_sdw: initialize ret in asoc_sdw_rt_amp_spk_rtd_init()
2025-02-11 13:13 ` Mark Brown
@ 2025-02-11 18:54 ` Pierre-Louis Bossart
2025-04-07 18:02 ` Kees Cook
0 siblings, 1 reply; 4+ messages in thread
From: Pierre-Louis Bossart @ 2025-02-11 18:54 UTC (permalink / raw)
To: Mark Brown, Ethan Carter Edwards
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-kernel, linux-hardening, Bard Liao, shumingf
On 2/11/25 07:13, Mark Brown wrote:
> On Mon, Feb 10, 2025 at 11:08:27PM -0500, Ethan Carter Edwards wrote:
>> There is a possibility for an uninitialized *ret* variable to be
>> returned in some code paths.
>>
>> Setting to 0 prevents a random value from being returned.
>
> That'll shut up the warning but is the warning trying to tell us that
> there's a logic bug somewhere in the function and we're for example
> forgetting to look at a return value in some path in the function?
The problematic code is this:
for_each_rtd_codec_dais(rtd, i, codec_dai) {
if (strstr(codec_dai->component->name_prefix, "-1"))
ret = snd_soc_dapm_add_routes(&card->dapm, rt_amp_map, 2);
else if (strstr(codec_dai->component->name_prefix, "-2"))
ret = snd_soc_dapm_add_routes(&card->dapm, rt_amp_map + 2, 2);
}
return ret;
I am not sure if it's possible that either the for_each does nothing or that the two branches are skipped, but certainly initializing the 'ret' value makes sense to me.
Bard, Shuming, what do you think?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ASoC: Intel: sof_sdw: initialize ret in asoc_sdw_rt_amp_spk_rtd_init()
2025-02-11 18:54 ` Pierre-Louis Bossart
@ 2025-04-07 18:02 ` Kees Cook
0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2025-04-07 18:02 UTC (permalink / raw)
To: Pierre-Louis Bossart
Cc: Mark Brown, Ethan Carter Edwards, Liam Girdwood, Jaroslav Kysela,
Takashi Iwai, linux-sound, linux-kernel, linux-hardening,
Bard Liao, shumingf
On Tue, Feb 11, 2025 at 12:54:52PM -0600, Pierre-Louis Bossart wrote:
> On 2/11/25 07:13, Mark Brown wrote:
> > On Mon, Feb 10, 2025 at 11:08:27PM -0500, Ethan Carter Edwards wrote:
> >> There is a possibility for an uninitialized *ret* variable to be
> >> returned in some code paths.
> >>
> >> Setting to 0 prevents a random value from being returned.
> >
> > That'll shut up the warning but is the warning trying to tell us that
> > there's a logic bug somewhere in the function and we're for example
> > forgetting to look at a return value in some path in the function?
>
> The problematic code is this:
>
> for_each_rtd_codec_dais(rtd, i, codec_dai) {
> if (strstr(codec_dai->component->name_prefix, "-1"))
> ret = snd_soc_dapm_add_routes(&card->dapm, rt_amp_map, 2);
> else if (strstr(codec_dai->component->name_prefix, "-2"))
> ret = snd_soc_dapm_add_routes(&card->dapm, rt_amp_map + 2, 2);
> }
>
> return ret;
>
> I am not sure if it's possible that either the for_each does nothing or that the two branches are skipped, but certainly initializing the 'ret' value makes sense to me.
>
> Bard, Shuming, what do you think?
I'm just skimming through patchwork and this patch doesn't seem to have
made any progress. What're next steps?
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-07 18:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-11 4:08 [PATCH] ASoC: Intel: sof_sdw: initialize ret in asoc_sdw_rt_amp_spk_rtd_init() Ethan Carter Edwards
2025-02-11 13:13 ` Mark Brown
2025-02-11 18:54 ` Pierre-Louis Bossart
2025-04-07 18:02 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox