Skip to contentSkip to conversation

sound/usb/format: silence uninitialized variable warnings

PATCH Superseded Dan Carpenter 3 participants 5 messages Aug 14, 2010 – Aug 15, 2010

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

PATCH 1/1 sound/usb/format: silence uninitialized variable warnings

Gcc complains that ret might be used uninitialized:

sound/usb/format.c: In function ‘snd_usb_parse_audio_format’:
sound/usb/format.c:354: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:354: note: ‘ret’ was declared here sound/usb/format.c:414: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:414: note: ‘ret’ was declared here

I suppose it could be if there is ever a UAC_VERSION_3 released. Anyway this patch is worthwhile if only to silence the gcc warning.

sound/usb/format.c +4 -2
index 4387f54..1400174 100644
@@ -351,7 +351,8 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
 {
 	struct usb_interface_descriptor *altsd = get_iface_desc(iface);
 	int protocol = altsd->bInterfaceProtocol;
-	int pcm_format, ret;
+	int pcm_format;
+	int ret = -EINVAL;
 
 	if (fmt->bFormatType = UAC_FORMAT_TYPE_III) {
 		/* FIXME: the format type is really IECxxx
@@ -411,9 +412,10 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
 				 int format, void *_fmt,
 				 struct usb_host_interface *iface)
 {
-	int brate, framesize, ret;
+	int brate, framesize;
 	struct usb_interface_descriptor *altsd = get_iface_desc(iface);
 	int protocol = altsd->bInterfaceProtocol;
+	int ret = -EINVAL;
 
 	switch (format) {
 	case UAC_FORMAT_TYPE_II_AC3:
#1 lore raw

At Sat, 14 Aug 2010 10:58:47 +0200,

Quoted 11 lines · Dan Carpenter

Gcc complains that ret might be used uninitialized:

sound/usb/format.c: In function ‘snd_usb_parse_audio_format’:
sound/usb/format.c:354: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:354: note: ‘ret’ was declared here sound/usb/format.c:414: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:414: note: ‘ret’ was declared here

I suppose it could be if there is ever a UAC_VERSION_3 released. Anyway this patch is worthwhile if only to silence the gcc warning.

It's nice to catch such possible bugs.
But, it'd be even nicer if kernel gives messages what's wrong instead of silent break-up.
Could you add error messages and repost the revised patch?

thanks,

Takashi

Quoted 30 lines
sound/usb/format.c +4 -2
index 4387f54..1400174 100644
@@ -351,7 +351,8 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
 {
 	struct usb_interface_descriptor *altsd = get_iface_desc(iface);
 	int protocol = altsd->bInterfaceProtocol;
-	int pcm_format, ret;
+	int pcm_format;
+	int ret = -EINVAL;
 
 	if (fmt->bFormatType = UAC_FORMAT_TYPE_III) {
 		/* FIXME: the format type is really IECxxx
@@ -411,9 +412,10 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
 				 int format, void *_fmt,
 				 struct usb_host_interface *iface)
 {
-	int brate, framesize, ret;
+	int brate, framesize;
 	struct usb_interface_descriptor *altsd = get_iface_desc(iface);
 	int protocol = altsd->bInterfaceProtocol;
+	int ret = -EINVAL;
 
 	switch (format) {
 	case UAC_FORMAT_TYPE_II_AC3:
#2 lore raw

PATCH v2 1/1 sound/usb/format: silence uninitialized variable warnings

Gcc complains that ret might be used uninitialized:

sound/usb/format.c: In function ‘snd_usb_parse_audio_format’:
sound/usb/format.c:354: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:354: note: ‘ret’ was declared here sound/usb/format.c:414: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:414: note: ‘ret’ was declared here

I suppose it could be uninitialized if there is ever a UAC_VERSION_3 released. Anyway this patch is worthwhile if only to silence the gcc warning.

---
V2: Totally different. Added printk()s

sound/usb/format.c +8 -0
index 4387f54..3a13754 100644
@@ -392,6 +392,10 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
 		/* fp->channels is already set in this case */
 		ret = parse_audio_format_rates_v2(chip, fp);
 		break;
+	default:
+		snd_printk(KERN_ERR "%d:%u:%d : invalid protocol version %d\n",
+			   chip->dev->devnum, fp->iface, fp->altsetting, protocol);
+		return -EINVAL;
 	}
 
 	if (fp->channels < 1) {
@@ -452,6 +456,10 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
 		ret = parse_audio_format_rates_v2(chip, fp);
 		break;
 	}
+	default:
+		snd_printk(KERN_ERR "%d:%u:%d : invalid protocol version %d\n",
+			   chip->dev->devnum, fp->iface, fp->altsetting, protocol);
+		return -EINVAL;
 	}
 
 	return ret;
Acked-by on v2 1/1
#3 lore raw
Quoted 8 lines · Dan Carpenter

Gcc complains that ret might be used uninitialized:

sound/usb/format.c: In function ‘snd_usb_parse_audio_format’:
sound/usb/format.c:354: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:354: note: ‘ret’ was declared here sound/usb/format.c:414: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:414: note: ‘ret’ was declared here

Quoted 5 lines

I suppose it could be uninitialized if there is ever a UAC_VERSION_3 released. Anyway this patch is worthwhile if only to silence the gcc warning.

Yes, such a check can't harm. You can have my

if you want :)

Thanks,
Daniel

Quoted 29 lines

---
V2: Totally different. Added printk()s

sound/usb/format.c +8 -0
index 4387f54..3a13754 100644
@@ -392,6 +392,10 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
 		/* fp->channels is already set in this case */
 		ret = parse_audio_format_rates_v2(chip, fp);
 		break;
+	default:
+		snd_printk(KERN_ERR "%d:%u:%d : invalid protocol version %d\n",
+			   chip->dev->devnum, fp->iface, fp->altsetting, protocol);
+		return -EINVAL;
 	}
 
 	if (fp->channels < 1) {
@@ -452,6 +456,10 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
 		ret = parse_audio_format_rates_v2(chip, fp);
 		break;
 	}
+	default:
+		snd_printk(KERN_ERR "%d:%u:%d : invalid protocol version %d\n",
+			   chip->dev->devnum, fp->iface, fp->altsetting, protocol);
+		return -EINVAL;
 	}
 
 	return ret;
Applied
#4 lore raw
In reply to Dan Carpenter

At Sat, 14 Aug 2010 19:29:53 +0200,

Quoted 9 lines · Dan Carpenter

Gcc complains that ret might be used uninitialized:

sound/usb/format.c: In function ‘snd_usb_parse_audio_format’:
sound/usb/format.c:354: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:354: note: ‘ret’ was declared here sound/usb/format.c:414: warning: ‘ret’ may be used uninitialized in this function sound/usb/format.c:414: note: ‘ret’ was declared here

Quoted 7 lines

I suppose it could be uninitialized if there is ever a UAC_VERSION_3 released. Anyway this patch is worthwhile if only to silence the gcc warning.

---
V2: Totally different. Added printk()s

Thanks, applied now.

Takashi

Quoted 28 lines
sound/usb/format.c +8 -0
index 4387f54..3a13754 100644
@@ -392,6 +392,10 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
 		/* fp->channels is already set in this case */
 		ret = parse_audio_format_rates_v2(chip, fp);
 		break;
+	default:
+		snd_printk(KERN_ERR "%d:%u:%d : invalid protocol version %d\n",
+			   chip->dev->devnum, fp->iface, fp->altsetting, protocol);
+		return -EINVAL;
 	}
 
 	if (fp->channels < 1) {
@@ -452,6 +456,10 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
 		ret = parse_audio_format_rates_v2(chip, fp);
 		break;
 	}
+	default:
+		snd_printk(KERN_ERR "%d:%u:%d : invalid protocol version %d\n",
+			   chip->dev->devnum, fp->iface, fp->altsetting, protocol);
+		return -EINVAL;
 	}
 
 	return ret;