Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 163871
b: refs/heads/master
c: 8bc2c1b
h: refs/heads/master
i:
  163869: 8d30824
  163867: 4dd49c9
  163863: 450229c
  163855: cec7749
  163839: 820908f
v: v3
  • Loading branch information
Alan Stern authored and Live-CD User committed Sep 19, 2009
1 parent fb51443 commit 89c2d07
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f5b0953a89fa3407fb293cc54ead7d8feec489e4
refs/heads/master: 8bc2c1b2daf95029658868cb1427baea2da87139
31 changes: 23 additions & 8 deletions trunk/drivers/usb/serial/usb-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,27 @@ static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
static DEFINE_MUTEX(table_lock);
static LIST_HEAD(usb_serial_driver_list);

/*
* Look up the serial structure. If it is found and it hasn't been
* disconnected, return with its disc_mutex held and its refcount
* incremented. Otherwise return NULL.
*/
struct usb_serial *usb_serial_get_by_index(unsigned index)
{
struct usb_serial *serial;

mutex_lock(&table_lock);
serial = serial_table[index];

if (serial)
kref_get(&serial->kref);
if (serial) {
mutex_lock(&serial->disc_mutex);
if (serial->disconnected) {
mutex_unlock(&serial->disc_mutex);
serial = NULL;
} else {
kref_get(&serial->kref);
}
}
mutex_unlock(&table_lock);
return serial;
}
Expand Down Expand Up @@ -123,8 +135,10 @@ static void return_serial(struct usb_serial *serial)

dbg("%s", __func__);

mutex_lock(&table_lock);
for (i = 0; i < serial->num_ports; ++i)
serial_table[serial->minor + i] = NULL;
mutex_unlock(&table_lock);
}

static void destroy_serial(struct kref *kref)
Expand Down Expand Up @@ -158,9 +172,7 @@ static void destroy_serial(struct kref *kref)

void usb_serial_put(struct usb_serial *serial)
{
mutex_lock(&table_lock);
kref_put(&serial->kref, destroy_serial);
mutex_unlock(&table_lock);
}

/*****************************************************************************
Expand Down Expand Up @@ -190,9 +202,12 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
return retval;
/* allow the driver to update it */
serial = usb_serial_get_by_index(tty->index);
if (serial->type->init_termios)
serial->type->init_termios(tty);
usb_serial_put(serial);
if (serial) {
if (serial->type->init_termios)
serial->type->init_termios(tty);
usb_serial_put(serial);
mutex_unlock(&serial->disc_mutex);
}
}
/* Final install (we use the default method) */
tty_driver_kref_get(driver);
Expand All @@ -218,7 +233,6 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
return -ENODEV;
}

mutex_lock(&serial->disc_mutex);
portNumber = tty->index - serial->minor;
port = serial->port[portNumber];
if (!port || serial->disconnected)
Expand Down Expand Up @@ -529,6 +543,7 @@ static int serial_proc_show(struct seq_file *m, void *v)

seq_putc(m, '\n');
usb_serial_put(serial);
mutex_unlock(&serial->disc_mutex);
}
return 0;
}
Expand Down

0 comments on commit 89c2d07

Please sign in to comment.