mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Benny Halevy <bhalevy@panasas.com>
To: Greg KH <greg@kroah.com>
Cc: linux-kernel@vger.kernel.org, Alen Cox <alan@lxorguk.ukuu.org.uk>,
	Benny Halevy <bhalevy@panasas.com>
Subject: [PATCH] usb: fix uninitialized variables in keyspan_pda
Date: Fri, 27 Jun 2008 10:58:54 +0300	[thread overview]
Message-ID: <1214553534-9970-1-git-send-email-bhalevy@panasas.com> (raw)
In-Reply-To: <4864944B.5020601@panasas.com>

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@panasas.com>
---
 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


  reply	other threads:[~2008-06-27  7:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-26 14:52 keyspan_pda.c use of keyspan_pda_get_modem_info Benny Halevy
2008-06-26 15:23 ` Alan Cox
2008-06-27  4:17   ` Greg KH
2008-06-27  7:18     ` Benny Halevy
2008-06-27  7:58       ` Benny Halevy [this message]
2008-06-27  8:58         ` [PATCH] usb: fix uninitialized variables in keyspan_pda Alan Cox
2008-06-27  9:22           ` Benny Halevy
2008-06-27 20:25             ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1214553534-9970-1-git-send-email-bhalevy@panasas.com \
    --to=bhalevy@panasas.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®