USB: serial: omninet: fix reference leaks at open
[pandora-kernel.git] / drivers / usb / serial / omninet.c
index 60f38d5..6665f5e 100644 (file)
@@ -152,6 +152,12 @@ static int omninet_attach(struct usb_serial *serial)
        struct omninet_data *od;
        struct usb_serial_port *port = serial->port[0];
 
+       /* The second bulk-out endpoint is used for writing. */
+       if (serial->num_bulk_out < 2) {
+               dev_err(&serial->interface->dev, "missing endpoints\n");
+               return -ENODEV;
+       }
+
        od = kmalloc(sizeof(struct omninet_data), GFP_KERNEL);
        if (!od) {
                dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n",
@@ -165,14 +171,10 @@ static int omninet_attach(struct usb_serial *serial)
 static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port)
 {
        struct usb_serial       *serial = port->serial;
-       struct usb_serial_port  *wport;
        int                     result = 0;
 
        dbg("%s - port %d", __func__, port->number);
 
-       wport = serial->port[1];
-       tty_port_tty_set(&wport->port, tty);
-
        /* Start reading from the device */
        usb_fill_bulk_urb(port->read_urb, serial->dev,
                        usb_rcvbulkpipe(serial->dev,
@@ -315,7 +317,7 @@ static int omninet_write_room(struct tty_struct *tty)
        int room = 0; /* Default: no room */
 
        /* FIXME: no consistent locking for write_urb_busy */
-       if (wport->write_urb_busy)
+       if (!wport->write_urb_busy)
                room = wport->bulk_out_size - OMNINET_HEADERLEN;
 
        dbg("%s - returns %d", __func__, room);