USB: sierra: add more checks on shutdown
authorGreg Kroah-Hartman <gregkh@suse.de>
Thu, 26 Apr 2007 07:12:01 +0000 (00:12 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 27 Apr 2007 20:28:40 +0000 (13:28 -0700)
This should help with any potential NULL pointer usages as reported by a
few users.

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

index 4865aff892e8593484e4aae3cbb2735f2106da14..644607de4c11a69f3e0e4a8d22b97e5f9fbcf473 100644 (file)
@@ -577,7 +577,12 @@ static void sierra_shutdown(struct usb_serial *serial)
        /* Stop reading/writing urbs */
        for (i = 0; i < serial->num_ports; ++i) {
                port = serial->port[i];
+               if (!port)
+                       continue;
                portdata = usb_get_serial_port_data(port);
+               if (!portdata)
+                       continue;
+
                for (j = 0; j < N_IN_URB; j++)
                        usb_unlink_urb(portdata->in_urbs[j]);
                for (j = 0; j < N_OUT_URB; j++)
@@ -587,7 +592,11 @@ static void sierra_shutdown(struct usb_serial *serial)
        /* Now free them */
        for (i = 0; i < serial->num_ports; ++i) {
                port = serial->port[i];
+               if (!port)
+                       continue;
                portdata = usb_get_serial_port_data(port);
+               if (!portdata)
+                       continue;
 
                for (j = 0; j < N_IN_URB; j++) {
                        if (portdata->in_urbs[j]) {
@@ -606,6 +615,8 @@ static void sierra_shutdown(struct usb_serial *serial)
        /* Now free per port private data */
        for (i = 0; i < serial->num_ports; i++) {
                port = serial->port[i];
+               if (!port)
+                       continue;
                kfree(usb_get_serial_port_data(port));
        }
 }