Skip to contentSkip to conversation

Fix for possible null pointer dereference in keyspan.c

PATCH In review Rickard Strandqvist 2 participants 3 messages May 15, 2014 – May 16, 2014

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

PATCH 1/1 Fix for possible null pointer dereference in keyspan.c

There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

---
 drivers/usb/serial/keyspan.c |    4 ++--

1 fil ändrad, 2 tillägg(+), 2 borttagningar(-)

drivers/usb/serial/keyspan.c +2 -2
index d3acaea..93cb7ce 100644
@@ -1535,14 +1535,14 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
 
 	this_urb = p_priv->outcont_urb;
 
-	dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
-
 		/* Make sure we have an urb then send the message */
 	if (this_urb == NULL) {
 		dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
 		return -1;
 	}
 
+	dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
+
 	/* Save reset port val for resend.
 	   Don't overwrite resend for open/close condition. */
 	if ((reset_port + 1) > p_priv->resend_cont)
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 1 line · Rickard Strandqvist

There is otherwise a risk of a possible null pointer dereference.

I don't think this can be triggered unless the URB allocation fails at probe, but let's move the offending line nonetheless.

I'll fix up the patch subject as well.

Quoted 6 lines

Was largely found by using a static code analysis program called cppcheck.

---
 drivers/usb/serial/keyspan.c |    4 ++--

1 fil ändrad, 2 tillägg(+), 2 borttagningar(-)

Diff stats in Swedish?! :)

Thanks,
Johan

Quoted 21 lines
drivers/usb/serial/keyspan.c +2 -2
index d3acaea..93cb7ce 100644
@@ -1535,14 +1535,14 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
 
 	this_urb = p_priv->outcont_urb;
 
-	dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
-
 		/* Make sure we have an urb then send the message */
 	if (this_urb == NULL) {
 		dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
 		return -1;
 	}
 
+	dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
+
 	/* Save reset port val for resend.
 	   Don't overwrite resend for open/close condition. */
 	if ((reset_port + 1) > p_priv->resend_cont)
#2 lore raw

PATCH 1/1 USB: keyspan: fix potential null pointer dereference

From: Rickard Strandqvist <[email protected]>

Move control-urb dereference to after NULL-check. There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

[Johan: modify commit message somewhat ]

---
 drivers/usb/serial/keyspan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/serial/keyspan.c +2 -2
index d3acaead5a81..93cb7cebda62 100644
@@ -1535,14 +1535,14 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
 
 	this_urb = p_priv->outcont_urb;
 
-	dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
-
 		/* Make sure we have an urb then send the message */
 	if (this_urb == NULL) {
 		dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
 		return -1;
 	}
 
+	dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
+
 	/* Save reset port val for resend.
 	   Don't overwrite resend for open/close condition. */
 	if ((reset_port + 1) > p_priv->resend_cont)
Signature · 1 line
1.8.5.5