[PATCH] usb: fix uninitialized variables in keyspan_pda

From: Benny Halevy
Date: Fri Jun 27 2008 - 03:59:56 EST


The compiler (gcc 4.3.0) warns that status might be used uninitialized
in keyspan_pda_tiocmget and keyspan_pda_tiocmset.

It is technically correct and therefore this patch initializes
status to 0 in both cases.

Note that keyspan_pda_get_modem_info sets *value only when
usb_control_msg returns rc > 0, otherwise it must
return an error rc < 0, and it must never return rc == 0, hence
a WARN_ON(rc == 0) was added in case usb_control_msg ever return 0.

Both its callers bail out for rc < 0 and use the value
of "status" in the rc >= 0 case. If the WARN_ON is ever seen,
status will be set to the initial value of 0.

Signed-off-by: Benny Halevy <bhalevy@xxxxxxxxxxx>
---
drivers/usb/serial/keyspan_pda.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index ff54203..97ce8a3 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -420,6 +420,7 @@ static int keyspan_pda_get_modem_info(struct usb_serial *serial,
3, /* get pins */
USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN,
0, 0, &data, 1, 2000);
+ WARN_ON(rc == 0);
if (rc > 0)
*value = data;
return rc;
@@ -441,7 +442,7 @@ static int keyspan_pda_tiocmget(struct usb_serial_port *port, struct file *file)
{
struct usb_serial *serial = port->serial;
int rc;
- unsigned char status;
+ unsigned char status = 0;
int value;

rc = keyspan_pda_get_modem_info(serial, &status);
@@ -462,7 +463,7 @@ static int keyspan_pda_tiocmset(struct usb_serial_port *port, struct file *file,
{
struct usb_serial *serial = port->serial;
int rc;
- unsigned char status;
+ unsigned char status = 0;

rc = keyspan_pda_get_modem_info(serial, &status);
if (rc < 0)
--
1.5.6.GIT

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/