Skip to contentSkip to conversation

usb: abort on exception path

PATCH In review Pan Bian 2 participants 2 messages Nov 29, 2016

Subsystems (2)
lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH 1/1 usb: abort on exception path

Function klsi_105_open() calls usb_control_msg() and checks its return value. When the return value is unexpected, it only assigns the error code to the return variable retval, but does not terminate the exception path. This patch fixes the bug by inserting "goto exit;" when the call to usb_control_msg() fails.

---
 drivers/usb/serial/kl5kusb105.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/serial/kl5kusb105.c +1 -0
index fc5d3a7..068919f 100644
@@ -311,6 +311,7 @@ static int  klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
 	if (rc < 0) {
 		dev_err(&port->dev, "Enabling read failed (error = %d)\n", rc);
 		retval = rc;
+		goto exit;
 	} else
 		dev_dbg(&port->dev, "%s - enabled reading\n", __func__);
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 7 lines · Pan Bian

Function klsi_105_open() calls usb_control_msg() and checks its return value. When the return value is unexpected, it only assigns the error code to the return variable retval, but does not terminate the exception path. This patch fixes the bug by inserting "goto exit;" when the call to usb_control_msg() fails.

Thanks for the patch.

It turns out there were more issues with the error handling in this function; for example, the URBs submitted by generic_open were never stopped on failure to read the line status a bit further down.

I fixed that up and rebased your patch on top.

I'll post both patches to the list shortly.

And next time, please include which driver you are changing in the patch summary and not just the subsystem prefix (e.g. use "USB: serial:
kl5kusb105: ...").

Quoted 9 lines
---
 drivers/usb/serial/kl5kusb105.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/serial/kl5kusb105.c +0 -0
index fc5d3a7..068919f 100644

drivers/usb/serial/kl5kusb105.c static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port) · line 316

Quoted 6 lines
drivers/usb/serial/kl5kusb105.c +1 -0
@@ -311,6 +311,7 @@ static int  klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
 	if (rc < 0) {
 		dev_err(&port->dev, "Enabling read failed (error = %d)\n", rc);
 		retval = rc;
+		goto exit;
 	} else
 		dev_dbg(&port->dev, "%s - enabled reading\n", __func__);

Thanks,
Johan