Skip to contentSkip to conversation

ASoC: uninitialized variable i used in wait_for_dc_servo

PATCH Axel Lin 2 participants 3 messages Sep 15, 2011

Subsystems (3)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

hi Mark,
I guess we need to initialize i to timeout value. comments?

sound/soc/codecs/wm8996.c +2 -1
index e5e4607..5aee9cb 100644
@@ -713,6 +713,7 @@ static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask)
 	snd_soc_write(codec, WM8996_DC_SERVO_2, mask);
 
 	/* Use the interrupt if possible */
+	i = timeout;
 	do {
 		if (i2c->irq) {
 			timeout = wait_for_completion_timeout(&wm8996->dcs_done,
@@ -722,7 +723,7 @@ static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask)
 
 		} else {
 			msleep(1);
-			if (--i) {
+			if (--i == 0) {
 				timeout = 0;
 				break;
 			}
#1 lore raw

sound/soc/codecs/wm8996.c static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask) · line 726

Quoted 6 lines · Axel Lin
sound/soc/codecs/wm8996.c +1 -1
@@ -722,7 +723,7 @@ static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask)
 
 		} else {
 			msleep(1);
-			if (--i) {
+			if (--i == 0) {

You should avoid making random stylistic changes that aren't needed when doing things like this.

author
#2 lore raw

2011/9/15 Mark Brown <[email protected]>:

Quoted 11 lines · Axel Lin

sound/soc/codecs/wm8996.c static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask) · line 726

Quoted 6 lines
sound/soc/codecs/wm8996.c +1 -1
@@ -722,7 +723,7 @@ static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask)
 
               } else {
                       msleep(1);
-                     if (--i) {
+                     if (--i == 0) {

You should avoid making random stylistic changes that aren't needed when doing things like this.

Ah. I didn't mean to change the coding style.
It's to reverse the logic of the if condition.

BTW, your fix looks good to me.

Regards,
Axel