Re: usb_serial_suspend(): buggy(?) code

Oliver Neukum <[email protected]>
Newsgroups gmane.linux.usb.devel,gmane.linux.kernel
Organization SuSE Linux
Message-ID <[email protected]>
Am Montag 23 Juli 2007 schrieb Adrian Bunk:
> Commit ec22559e0b7a05283a3413bda5d177e42c950e23 added the following 
> function to drivers/usb/serial/usb-serial.c:
> 
[..]
> 
> The Coverity checker spotted the inconsequent NULL checking for "serial".
> 
> Looking at the code it also doesn't seem to have been intended to always 
> return 0.

Coverity is right. The check for NULL is wrongly done and the error
return is lost.

	Regards
		Oliver
Signed-off-by: Oliver Neukum <[email protected]>
--

--- a/drivers/usb/serial/usb-serial.c	2007-07-23 08:47:35.000000000 +0200
+++ b/drivers/usb/serial/usb-serial.c	2007-07-23 08:49:20.000000000 +0200
@@ -1077,16 +1077,17 @@ int usb_serial_suspend(struct usb_interf
 	struct usb_serial_port *port;
 	int i, r = 0;
 
-	if (serial) {
-		for (i = 0; i < serial->num_ports; ++i) {
-			port = serial->port[i];
-			if (port)
-				kill_traffic(port);
-		}
+	if (!serial) /* device has been disconnected */
+		return 0;
+
+	for (i = 0; i < serial->num_ports; ++i) {
+		port = serial->port[i];
+		if (port)
+			kill_traffic(port);
 	}
 
 	if (serial->type->suspend)
-		serial->type->suspend(serial, message);
+		r = serial->type->suspend(serial, message);
 
 	return r;
 }

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.