Skip to contentSkip to conversation

USB: 6fire: signedness bug in usb6fire_pcm_prepare()

PATCH In review Dan Carpenter 2 participants 2 messages Feb 7, 2011

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

PATCH 1/1 USB: 6fire: signedness bug in usb6fire_pcm_prepare()

rt->rate is an unsigned char so it's never equal to -1. It's not a huge problem because the invalid rate is caught inside the call to usb6fire_pcm_set_rate() which returns -EINVAL. But if we fix the test then it prints out the correct error message so that's good.

sound/usb/6fire/pcm.c +1 -2
index 705c88e..ba62c74 100644
@@ -493,13 +493,12 @@ static int usb6fire_pcm_prepare(struct snd_pcm_substream *alsa_sub)
 	sub->period_off = 0;
 
 	if (rt->stream_state = STREAM_DISABLED) {
-		rt->rate = -1;
 		for (i = 0; i < ARRAY_SIZE(rates); i++)
 			if (alsa_rt->rate = rates[i]) {
 				rt->rate = i;
 				break;
 			}
-		if (rt->rate = -1) {
+		if (i = ARRAY_SIZE(rates)) {
 			mutex_unlock(&rt->stream_mutex);
 			snd_printk("invalid rate %d in prepare.\n",
 					alsa_rt->rate);
#1 lore raw

At Mon, 7 Feb 2011 20:25:19 +0300,

Quoted 7 lines · Dan Carpenter

rt->rate is an unsigned char so it's never equal to -1. It's not a huge problem because the invalid rate is caught inside the call to usb6fire_pcm_set_rate() which returns -EINVAL. But if we fix the test then it prints out the correct error message so that's good.

Applied now. Thanks.

Takashi

Quoted 20 lines
sound/usb/6fire/pcm.c +1 -2
index 705c88e..ba62c74 100644
@@ -493,13 +493,12 @@ static int usb6fire_pcm_prepare(struct snd_pcm_substream *alsa_sub)
 	sub->period_off = 0;
 
 	if (rt->stream_state = STREAM_DISABLED) {
-		rt->rate = -1;
 		for (i = 0; i < ARRAY_SIZE(rates); i++)
 			if (alsa_rt->rate = rates[i]) {
 				rt->rate = i;
 				break;
 			}
-		if (rt->rate = -1) {
+		if (i = ARRAY_SIZE(rates)) {
 			mutex_unlock(&rt->stream_mutex);
 			snd_printk("invalid rate %d in prepare.\n",
 					alsa_rt->rate);