ALSA: pci: lx6464es: fix a debug loop
Subsystems (2)
PATCH 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.
--- sound/pci/lx6464es/lx_core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
sound/pci/lx6464es/lx_core.c +5 -7
@@ -493,13 +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 < 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 ); }mutex_unlock (&chip->msg_lock);
Signature · 1 line
2.35.1
Quoted 19 lines · Dan Carpenter
This loop accidentally reuses the "i" iterator for both the inside and the outside loop. The value of
MAX_STREAM_BUFFERis 5. I believe thatchip->rmh.stat_lenis 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.Fixes 8e6320064c33 ("ALSA: lx_core: Remove useless #if 0 .. #endif")Signed-off-by Dan Carpenter <[email protected]>--- sound/pci/lx6464es/lx_core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)sound/pci/lx6464es/lx_core.c +0
-0@@ -493,13 +493,11 @@ int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture, dev_dbg(chip->card->dev,
sound/pci/lx6464es/lx_core.c int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture, · line 496
Quoted 10 lines
sound/pci/lx6464es/lx_core.c +1
-7"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 < chip->rmh.stat_len; ++i)
Judging from the previous lines, the access over MAX_STREAM_BUFFER might be unsafe. So I guess a more safer change would be something like:
for (i = 0; i < MAX_STREAM_BUFFER && chip->rmh.stat_len; ++i)
Care to resubmit with it?
Thanks!
Takashi
Quoted 36 lines · Takashi Iwai
Quoted 19 lines · Dan Carpenter
This loop accidentally reuses the "i" iterator for both the inside and the outside loop. The value of
MAX_STREAM_BUFFERis 5. I believe thatchip->rmh.stat_lenis 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.Fixes 8e6320064c33 ("ALSA: lx_core: Remove useless #if 0 .. #endif")Signed-off-by Dan Carpenter <[email protected]>--- sound/pci/lx6464es/lx_core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)sound/pci/lx6464es/lx_core.c +0
-0@@ -493,13 +493,11 @@ int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture, dev_dbg(chip->card->dev,sound/pci/lx6464es/lx_core.c int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture, · line 496
Quoted 10 lines
sound/pci/lx6464es/lx_core.c +1
-7"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 < chip->rmh.stat_len; ++i)Judging from the previous lines, the access over
MAX_STREAM_BUFFERmight be unsafe. So I guess a more safer change would be something like:
Quoted 1 line
for (i = 0; i < MAX_STREAM_BUFFER && chip->rmh.stat_len; ++i)
&& i < chip->rmh.stat_len
TBH, I'd prefer to just delete all this code since it used be ifdef 0.
But I'll resend as you have suggested.
regards,
dan carpenter