Skip to contentSkip to conversation

ALSA: pci: lx6464es: fix a debug loop

PATCH Applied Dan Carpenter 2 participants 2 messages Jan 31, 2023 – Feb 1, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ALSA: pci: lx6464es: fix a debug loop

This loop accidentally reuses the "i" iterator for both the inside and the outside loop. The value of MAX_STREAM_BUFFER is 5. I believe that chip->rmh.stat_len is in the 2-12 range. If the value of .stat_len is 4 or more then it will loop exactly one time, but if it's less then it is a forever loop.

It looks like it was supposed to combined into one loop where conditions are checked.

Fixes 8e6320064c33 ("ALSA: lx_core: Remove useless #if 0 .. #endif")

---
v2: In the first version I just deleted the outside loop but that was not the correct fix. Combine the conditions instead.

 sound/pci/lx6464es/lx_core.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
sound/pci/lx6464es/lx_core.c +5 -6
index d3f58a3d17fb..b5b0d43bb8dc 100644
@@ -493,12 +493,11 @@ int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture,
 		dev_dbg(chip->card->dev,
 			"CMD_08_ASK_BUFFERS: needed %d, freed %d\n",
 			    *r_needed, *r_freed);
-		for (i = 0; i < MAX_STREAM_BUFFER; ++i) {
-			for (i = 0; i != chip->rmh.stat_len; ++i)
-				dev_dbg(chip->card->dev,
-					"  stat[%d]: %x, %x\n", i,
-					    chip->rmh.stat[i],
-					    chip->rmh.stat[i] & MASK_DATA_SIZE);
+		for (i = 0; i < MAX_STREAM_BUFFER && i < chip->rmh.stat_len;
+		     ++i) {
+			dev_dbg(chip->card->dev, "  stat[%d]: %x, %x\n", i,
+				chip->rmh.stat[i],
+				chip->rmh.stat[i] & MASK_DATA_SIZE);
 		}
 	}
 
Signature · 1 line
2.35.1
Applied
#1 lore raw
Quoted 7 lines · Dan Carpenter

This loop accidentally reuses the "i" iterator for both the inside and the outside loop. The value of MAX_STREAM_BUFFER is 5. I believe that chip->rmh.stat_len is in the 2-12 range. If the value of .stat_len is 4 or more then it will loop exactly one time, but if it's less then it is a forever loop.

Quoted 8 lines

It looks like it was supposed to combined into one loop where conditions are checked.

Fixes 8e6320064c33 ("ALSA: lx_core: Remove useless #if 0 .. #endif")

---
v2: In the first version I just deleted the outside loop but that was not the correct fix. Combine the conditions instead.

Thanks, applied.

Takashi