USB: fix usb_serial_suspend(): buggy code
authorOliver Neukum <oneukum@suse.de>
Mon, 23 Jul 2007 06:58:39 +0000 (08:58 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 30 Jul 2007 20:27:45 +0000 (13:27 -0700)
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.

Signed-off-by: Oliver Neukum <oneukum@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/serial/usb-serial.c

index a3665659d13b32636914368429c0be0d6998e35d..5e1cf78c77867803c533d40da2dc7e67aae3e0b8 100644 (file)
@@ -1077,16 +1077,17 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
        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;
 }