ASoC: rt-sdw-common: Fix bit-wise or'ing of values into uninitialized variable ret
Subsystems (4)
PATCH 1/1 ASoC: rt-sdw-common: Fix bit-wise or'ing of values into uninitialized variable ret
There are a handful of bit-wise or'ing of values into the uninitialized variable ret resulting in garbage results. Fix this by ininitializing ret to zero.
--- sound/soc/codecs/rt-sdw-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/rt-sdw-common.c +1 -1
@@ -101,21 +101,21 @@ EXPORT_SYMBOL_GPL(rt_sdca_index_update_bits);* rt_sdca_btn_type - Decision of button type. * * @buffer: UMP message buffer. * * A button type will be returned regarding to buffer, * it returns zero if buffer cannot be recognized. */ int rt_sdca_btn_type (unsigned char *buffer) {u8 btn_type =0 ; -int ret; +int ret =0 ; btn_type |= buffer[0 ] &0xf ; btn_type |= (buffer[0 ] >>4 ) &0xf ; btn_type |= buffer[1 ] &0xf ; btn_type |= (buffer[1 ] >>4 ) &0xf ;if (btn_type &BIT (0 )) ret |=SND_JACK_BTN_2 ;if (btn_type &BIT (1 )) ret |=SND_JACK_BTN_3 ;
Signature · 1 line
2.39.5
Mark Brown
maintainerQuoted 3 lines · Colin Ian King
There are a handful of bit-wise or'ing of values into the uninitialized variable ret resulting in garbage results. Fix this by ininitializing ret to zero.
I'm very disappinted in the compiler for not noticing this :(
Quoted 6 lines · Mark Brown
Quoted 3 lines · Colin Ian King
There are a handful of bit-wise or'ing of values into the uninitialized variable ret resulting in garbage results. Fix this by ininitializing ret to zero.
I'm very disappinted in the compiler for not noticing this :(
We disabled GCC's uninitialized variable check years ago before we enabled -Werror. Clang does catch this.
CC sound/soc/codecs/rt-sdw-common.osound/soc/codecs/rt-sdw-common.c:119:3: warning: variable 'ret' is uninitialized when used here [-Wuninitialized]
ret |= SND_JACK_BTN_2;
^~~
sound/soc/codecs/rt-sdw-common.c:111:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 0regards,
dan carpenter
Quoted 14 lines
-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Wednesday, October 9, 2024 1:04 AM
To: Colin Ian King <[email protected]>
Cc: Oder Chiou <[email protected]>; Liam Girdwood <[email protected]>; Jaroslav Kysela <[email protected]>; Takashi Iwai <[email protected]>; Jack Yu <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH][next] ASoC: rt-sdw-common: Fix bit-wise or'ing of values into uninitialized variable ret
Quoted 6 lines
Quoted 3 lines · Colin Ian King
There are a handful of bit-wise or'ing of values into the uninitialized variable ret resulting in garbage results. Fix this by ininitializing ret to zero.
I'm very disappinted in the compiler for not noticing this :(
I'm sorry for such mistake. I've sent a patch to fix this yesterday, please refer attachment.
Fix issue of warning messages caused by some variables.
--- sound/soc/codecs/rt-sdw-common.c | 2 +- sound/soc/codecs/rt721-sdca.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
sound/soc/codecs/rt-sdw-common.c +1 -1
@@ -108,7 +108,7 @@ EXPORT_SYMBOL_GPL(rt_sdca_index_update_bits);int rt_sdca_btn_type (unsigned char *buffer) {u8 btn_type =0 ; -int ret; +int ret =0 ; btn_type |= buffer[0 ] &0xf ; btn_type |= (buffer[0 ] >>4 ) &0xf ;
sound/soc/codecs/rt721-sdca.c +2 -2
@@ -30,7 +30,7 @@ static void rt721_sdca_jack_detect_handler(struct work_struct *work) {struct rt721_sdca_priv *rt721 = container_of(work, struct rt721_sdca_priv, jack_detect_work.work); -int btn_type =0 , ret; +int btn_type =0 ;if (!rt721->hs_jack)return ;
@@ -42,7 +42,7 @@ static void rt721_sdca_jack_detect_handler(struct work_struct *work)if (rt721->scp_sdca_stat1 &SDW_SCP_SDCA_INT_SDCA_6 ) { rt721->jack_type =rt_sdca_headset_detect (rt721->regmap,RT721_SDCA_ENT_GE49 ); -if (ret <0 ) +if (rt721->jack_type <0 )return ; }
Signature · 1 line
2.34.1