Skip to contentSkip to conversation

ASoC: rt-sdw-common: Enhance switch case to prevent uninitialized variable

PATCH Superseded Jack Yu 2 participants 2 messages Oct 14, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jack Yu

author
#0 lore raw

PATCH 1/1 ASoC: rt-sdw-common: Enhance switch case to prevent uninitialized variable

If det_mode is not 0, 3 or 5 then function will return jack_type with an uninitialzed value.
Enhance switch case to prevent uninitialized variable issue.

---
 sound/soc/codecs/rt-sdw-common.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
sound/soc/codecs/rt-sdw-common.c +2 -3
index a422da6cf702..3ec576c576be 100644
@@ -150,15 +150,14 @@ int rt_sdca_headset_detect(struct regmap *map, unsigned int entity_id)
 		goto io_error;
 
 	switch (det_mode) {
-	case 0x00:
-		jack_type = 0;
-		break;
 	case 0x03:
 		jack_type = SND_JACK_HEADPHONE;
 		break;
 	case 0x05:
 		jack_type = SND_JACK_HEADSET;
 		break;
+	default:
+		jack_type = 0;
 	}
 
 	/* write selected_mode */
Signature · 1 line
2.34.1
maintainer
#1 lore raw

sound/soc/codecs/rt-sdw-common.c int rt_sdca_headset_detect(struct regmap *map, unsigned int entity_id) · line 161

Quoted 6 lines · Jack Yu
sound/soc/codecs/rt-sdw-common.c +2 -0
 	case 0x05:
 		jack_type = SND_JACK_HEADSET;
 		break;
+	default:
+		jack_type = 0;
 	}

Even though it's a bit redundant you should still have a break; here for the kernel coding style, missing it might upset some linters.