USB: serial: io_edgeport: fix NULL-deref at open
[pandora-kernel.git] / drivers / usb / serial / qcserial.c
index b9bb247..e8c4f0c 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
+#include <linux/module.h>
 #include <linux/usb.h>
 #include <linux/usb/serial.h>
 #include <linux/slab.h>
 
 static int debug;
 
+#define DEVICE_G1K(v, p) \
+       USB_DEVICE(v, p), .driver_info = 1
+
 static const struct usb_device_id id_table[] = {
-       {USB_DEVICE(0x05c6, 0x9211)},   /* Acer Gobi QDL device */
-       {USB_DEVICE(0x05c6, 0x9212)},   /* Acer Gobi Modem Device */
-       {USB_DEVICE(0x03f0, 0x1f1d)},   /* HP un2400 Gobi Modem Device */
-       {USB_DEVICE(0x03f0, 0x201d)},   /* HP un2400 Gobi QDL Device */
-       {USB_DEVICE(0x03f0, 0x371d)},   /* HP un2430 Mobile Broadband Module */
-       {USB_DEVICE(0x04da, 0x250d)},   /* Panasonic Gobi Modem device */
-       {USB_DEVICE(0x04da, 0x250c)},   /* Panasonic Gobi QDL device */
-       {USB_DEVICE(0x413c, 0x8172)},   /* Dell Gobi Modem device */
-       {USB_DEVICE(0x413c, 0x8171)},   /* Dell Gobi QDL device */
-       {USB_DEVICE(0x1410, 0xa001)},   /* Novatel Gobi Modem device */
-       {USB_DEVICE(0x1410, 0xa008)},   /* Novatel Gobi QDL device */
-       {USB_DEVICE(0x0b05, 0x1776)},   /* Asus Gobi Modem device */
-       {USB_DEVICE(0x0b05, 0x1774)},   /* Asus Gobi QDL device */
-       {USB_DEVICE(0x19d2, 0xfff3)},   /* ONDA Gobi Modem device */
-       {USB_DEVICE(0x19d2, 0xfff2)},   /* ONDA Gobi QDL device */
-       {USB_DEVICE(0x1557, 0x0a80)},   /* OQO Gobi QDL device */
-       {USB_DEVICE(0x05c6, 0x9001)},   /* Generic Gobi Modem device */
-       {USB_DEVICE(0x05c6, 0x9002)},   /* Generic Gobi Modem device */
-       {USB_DEVICE(0x05c6, 0x9202)},   /* Generic Gobi Modem device */
-       {USB_DEVICE(0x05c6, 0x9203)},   /* Generic Gobi Modem device */
-       {USB_DEVICE(0x05c6, 0x9222)},   /* Generic Gobi Modem device */
-       {USB_DEVICE(0x05c6, 0x9008)},   /* Generic Gobi QDL device */
-       {USB_DEVICE(0x05c6, 0x9009)},   /* Generic Gobi Modem device */
-       {USB_DEVICE(0x05c6, 0x9201)},   /* Generic Gobi QDL device */
-       {USB_DEVICE(0x05c6, 0x9221)},   /* Generic Gobi QDL device */
-       {USB_DEVICE(0x05c6, 0x9231)},   /* Generic Gobi QDL device */
-       {USB_DEVICE(0x1f45, 0x0001)},   /* Unknown Gobi QDL device */
+       /* Gobi 1000 devices */
+       {DEVICE_G1K(0x05c6, 0x9211)},   /* Acer Gobi QDL device */
+       {DEVICE_G1K(0x05c6, 0x9212)},   /* Acer Gobi Modem Device */
+       {DEVICE_G1K(0x03f0, 0x1f1d)},   /* HP un2400 Gobi Modem Device */
+       {DEVICE_G1K(0x03f0, 0x201d)},   /* HP un2400 Gobi QDL Device */
+       {DEVICE_G1K(0x04da, 0x250d)},   /* Panasonic Gobi Modem device */
+       {DEVICE_G1K(0x04da, 0x250c)},   /* Panasonic Gobi QDL device */
+       {DEVICE_G1K(0x413c, 0x8172)},   /* Dell Gobi Modem device */
+       {DEVICE_G1K(0x413c, 0x8171)},   /* Dell Gobi QDL device */
+       {DEVICE_G1K(0x1410, 0xa001)},   /* Novatel/Verizon USB-1000 */
+       {DEVICE_G1K(0x1410, 0xa002)},   /* Novatel Gobi Modem device */
+       {DEVICE_G1K(0x1410, 0xa003)},   /* Novatel Gobi Modem device */
+       {DEVICE_G1K(0x1410, 0xa004)},   /* Novatel Gobi Modem device */
+       {DEVICE_G1K(0x1410, 0xa005)},   /* Novatel Gobi Modem device */
+       {DEVICE_G1K(0x1410, 0xa006)},   /* Novatel Gobi Modem device */
+       {DEVICE_G1K(0x1410, 0xa007)},   /* Novatel Gobi Modem device */
+       {DEVICE_G1K(0x1410, 0xa008)},   /* Novatel Gobi QDL device */
+       {DEVICE_G1K(0x0b05, 0x1776)},   /* Asus Gobi Modem device */
+       {DEVICE_G1K(0x0b05, 0x1774)},   /* Asus Gobi QDL device */
+       {DEVICE_G1K(0x19d2, 0xfff3)},   /* ONDA Gobi Modem device */
+       {DEVICE_G1K(0x19d2, 0xfff2)},   /* ONDA Gobi QDL device */
+       {DEVICE_G1K(0x1557, 0x0a80)},   /* OQO Gobi QDL device */
+       {DEVICE_G1K(0x05c6, 0x9001)},   /* Generic Gobi Modem device */
+       {DEVICE_G1K(0x05c6, 0x9002)},   /* Generic Gobi Modem device */
+       {DEVICE_G1K(0x05c6, 0x9202)},   /* Generic Gobi Modem device */
+       {DEVICE_G1K(0x05c6, 0x9203)},   /* Generic Gobi Modem device */
+       {DEVICE_G1K(0x05c6, 0x9222)},   /* Generic Gobi Modem device */
+       {DEVICE_G1K(0x05c6, 0x9008)},   /* Generic Gobi QDL device */
+       {DEVICE_G1K(0x05c6, 0x9009)},   /* Generic Gobi Modem device */
+       {DEVICE_G1K(0x05c6, 0x9201)},   /* Generic Gobi QDL device */
+       {DEVICE_G1K(0x05c6, 0x9221)},   /* Generic Gobi QDL device */
+       {DEVICE_G1K(0x05c6, 0x9231)},   /* Generic Gobi QDL device */
+       {DEVICE_G1K(0x1f45, 0x0001)},   /* Unknown Gobi QDL device */
+       {DEVICE_G1K(0x1bc7, 0x900e)},   /* Telit Gobi QDL device */
+
+       /* Gobi 2000 devices */
+       {USB_DEVICE(0x1410, 0xa010)},   /* Novatel Gobi 2000 QDL device */
+       {USB_DEVICE(0x1410, 0xa011)},   /* Novatel Gobi 2000 QDL device */
+       {USB_DEVICE(0x1410, 0xa012)},   /* Novatel Gobi 2000 QDL device */
+       {USB_DEVICE(0x1410, 0xa013)},   /* Novatel Gobi 2000 QDL device */
+       {USB_DEVICE(0x1410, 0xa014)},   /* Novatel Gobi 2000 QDL device */
        {USB_DEVICE(0x413c, 0x8185)},   /* Dell Gobi 2000 QDL device (N0218, VU936) */
        {USB_DEVICE(0x413c, 0x8186)},   /* Dell Gobi 2000 Modem device (N0218, VU936) */
        {USB_DEVICE(0x05c6, 0x9208)},   /* Generic Gobi 2000 QDL device */
@@ -85,7 +103,25 @@ static const struct usb_device_id id_table[] = {
        {USB_DEVICE(0x16d8, 0x8002)},   /* CMDTech Gobi 2000 Modem device (VU922) */
        {USB_DEVICE(0x05c6, 0x9204)},   /* Gobi 2000 QDL device */
        {USB_DEVICE(0x05c6, 0x9205)},   /* Gobi 2000 Modem device */
+
+       /* Gobi 3000 devices */
+       {USB_DEVICE(0x03f0, 0x371d)},   /* HP un2430 Gobi 3000 QDL */
+       {USB_DEVICE(0x05c6, 0x920c)},   /* Gobi 3000 QDL */
+       {USB_DEVICE(0x05c6, 0x920d)},   /* Gobi 3000 Composite */
+       {USB_DEVICE(0x1410, 0xa020)},   /* Novatel Gobi 3000 QDL */
+       {USB_DEVICE(0x1410, 0xa021)},   /* Novatel Gobi 3000 Composite */
+       {USB_DEVICE(0x413c, 0x8193)},   /* Dell Gobi 3000 QDL */
+       {USB_DEVICE(0x413c, 0x8194)},   /* Dell Gobi 3000 Composite */
+       {USB_DEVICE(0x1199, 0x9010)},   /* Sierra Wireless Gobi 3000 QDL */
+       {USB_DEVICE(0x1199, 0x9012)},   /* Sierra Wireless Gobi 3000 QDL */
        {USB_DEVICE(0x1199, 0x9013)},   /* Sierra Wireless Gobi 3000 Modem device (MC8355) */
+       {USB_DEVICE(0x1199, 0x9014)},   /* Sierra Wireless Gobi 3000 QDL */
+       {USB_DEVICE(0x1199, 0x9015)},   /* Sierra Wireless Gobi 3000 Modem device */
+       {USB_DEVICE(0x1199, 0x9018)},   /* Sierra Wireless Gobi 3000 QDL */
+       {USB_DEVICE(0x1199, 0x9019)},   /* Sierra Wireless Gobi 3000 Modem device */
+       {USB_DEVICE(0x12D1, 0x14F0)},   /* Sony Gobi 3000 QDL */
+       {USB_DEVICE(0x12D1, 0x14F1)},   /* Sony Gobi 3000 Composite */
+       {USB_DEVICE(0x0AF0, 0x8120)},   /* Option GTM681W */
        { }                             /* Terminating entry */
 };
 MODULE_DEVICE_TABLE(usb, id_table);
@@ -107,8 +143,10 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
        int retval = -ENODEV;
        __u8 nintf;
        __u8 ifnum;
+       bool is_gobi1k = id->driver_info ? true : false;
 
        dbg("%s", __func__);
+       dbg("Is Gobi 1000 = %d", is_gobi1k);
 
        nintf = serial->dev->actconfig->desc.bNumInterfaces;
        dbg("Num Interfaces = %d", nintf);
@@ -156,15 +194,25 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
 
        case 3:
        case 4:
-               /* Composite mode */
-               /* ifnum == 0 is a broadband network adapter */
-               if (ifnum == 1) {
-                       /*
-                        * Diagnostics Monitor (serial line 9600 8N1)
-                        * Qualcomm DM protocol
-                        * use "libqcdm" (ModemManager) for communication
-                        */
-                       dbg("Diagnostics Monitor found");
+               /* Composite mode; don't bind to the QMI/net interface as that
+                * gets handled by other drivers.
+                */
+
+               /* Gobi 1K USB layout:
+                * 0: serial port (doesn't respond)
+                * 1: serial port (doesn't respond)
+                * 2: AT-capable modem port
+                * 3: QMI/net
+                *
+                * Gobi 2K+ USB layout:
+                * 0: QMI/net
+                * 1: DM/DIAG (use libqcdm from ModemManager for communication)
+                * 2: AT-capable modem port
+                * 3: NMEA
+                */
+
+               if (ifnum == 1 && !is_gobi1k) {
+                       dbg("Gobi 2K+ DM/DIAG interface found");
                        retval = usb_set_interface(serial->dev, ifnum, 0);
                        if (retval < 0) {
                                dev_err(&serial->dev->dev,
@@ -183,13 +231,13 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
                                retval = -ENODEV;
                                kfree(data);
                        }
-               } else if (ifnum==3) {
+               } else if (ifnum==3 && !is_gobi1k) {
                        /*
                         * NMEA (serial line 9600 8N1)
                         * # echo "\$GPS_START" > /dev/ttyUSBx
                         * # echo "\$GPS_STOP"  > /dev/ttyUSBx
                         */
-                       dbg("NMEA GPS interface found");
+                       dbg("Gobi 2K+ NMEA GPS interface found");
                        retval = usb_set_interface(serial->dev, ifnum, 0);
                        if (retval < 0) {
                                dev_err(&serial->dev->dev,