linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [media] m920x: Fix uninitialized variable warning
@ 2013-03-31 10:12 Jean Delvare
  2013-03-31 11:16 ` [PATCH v2] " Jean Delvare
  0 siblings, 1 reply; 2+ messages in thread
From: Jean Delvare @ 2013-03-31 10:12 UTC (permalink / raw)
  To: Linux Media; +Cc: Mauro Carvalho Chehab, Antonio Ospite

drivers/media/usb/dvb-usb/m920x.c:91:6: warning: "ret" may be used uninitialized in this function [-Wuninitialized]
drivers/media/usb/dvb-usb/m920x.c:70:6: note: "ret" was declared here

This is real, if a remote control has an empty initialization sequence
we would get success or failure randomly.

OTOH the initialization of ret in m920x_init is needless, the function
returns with an error as soon as an error happens, so the last return
can only be a success and we can hard-code 0 there.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Antonio Ospite <ospite@studenti.unina.it>
---
Untested, I don't have the hardware.

 drivers/media/usb/dvb-usb/m920x.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--- linux-3.9-rc4.orig/drivers/media/usb/dvb-usb/m920x.c	2013-03-05 10:33:29.497926362 +0100
+++ linux-3.9-rc4/drivers/media/usb/dvb-usb/m920x.c	2013-03-31 11:25:54.009509019 +0200
@@ -67,7 +67,8 @@ static inline int m920x_write(struct usb
 static inline int m920x_write_seq(struct usb_device *udev, u8 request,
 				  struct m920x_inits *seq)
 {
-	int ret;
+	int ret = 0;
+
 	while (seq->address) {
 		ret = m920x_write(udev, request, seq->data, seq->address);
 		if (ret != 0)
@@ -81,7 +82,7 @@ static inline int m920x_write_seq(struct
 
 static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
 {
-	int ret = 0, i, epi, flags = 0;
+	int ret, i, epi, flags = 0;
 	int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
 
 	/* Remote controller init. */
@@ -124,7 +125,7 @@ static int m920x_init(struct dvb_usb_dev
 		}
 	}
 
-	return ret;
+	return 0;
 }
 
 static int m920x_init_ep(struct usb_interface *intf)


-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2] [media] m920x: Fix uninitialized variable warning
  2013-03-31 10:12 [media] m920x: Fix uninitialized variable warning Jean Delvare
@ 2013-03-31 11:16 ` Jean Delvare
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2013-03-31 11:16 UTC (permalink / raw)
  To: Linux Media; +Cc: Mauro Carvalho Chehab, Antonio Ospite

drivers/media/usb/dvb-usb/m920x.c:91:6: warning: "ret" may be used uninitialized in this function [-Wuninitialized]
drivers/media/usb/dvb-usb/m920x.c:70:6: note: "ret" was declared here

This is real, if a remote control has an empty initialization sequence
we would get success or failure randomly.

OTOH the initialization of ret in m920x_init is needless, the function
returns with an error as soon as an error happens, so the last return
can only be a success and we can hard-code 0 there.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: Antonio Ospite <ospite@studenti.unina.it>
---
An even better and simpler fix, avoids a useless initialization in most
cases and is more consistent. And this is what gcc optimizes the code
to anyway.

 drivers/media/usb/dvb-usb/m920x.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- linux-3.9-rc4.orig/drivers/media/usb/dvb-usb/m920x.c	2013-03-31 12:03:26.473890149 +0200
+++ linux-3.9-rc4/drivers/media/usb/dvb-usb/m920x.c	2013-03-31 13:11:59.973117266 +0200
@@ -76,12 +76,12 @@ static inline int m920x_write_seq(struct
 		seq++;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
 {
-	int ret = 0, i, epi, flags = 0;
+	int ret, i, epi, flags = 0;
 	int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
 
 	/* Remote controller init. */
@@ -124,7 +124,7 @@ static int m920x_init(struct dvb_usb_dev
 		}
 	}
 
-	return ret;
+	return 0;
 }
 
 static int m920x_init_ep(struct usb_interface *intf)

-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-31 11:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-31 10:12 [media] m920x: Fix uninitialized variable warning Jean Delvare
2013-03-31 11:16 ` [PATCH v2] " Jean Delvare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).