aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/usb-serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/usb-serial.c')
-rw-r--r--drivers/usb/serial/usb-serial.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 5bc023c73893..8bc8337c99c4 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -30,6 +30,7 @@
30#include <linux/list.h> 30#include <linux/list.h>
31#include <linux/smp_lock.h> 31#include <linux/smp_lock.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <asm/semaphore.h>
33#include <linux/usb.h> 34#include <linux/usb.h>
34#include "usb-serial.h" 35#include "usb-serial.h"
35#include "pl2303.h" 36#include "pl2303.h"
@@ -190,6 +191,9 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
190 port = serial->port[portNumber]; 191 port = serial->port[portNumber];
191 if (!port) 192 if (!port)
192 return -ENODEV; 193 return -ENODEV;
194
195 if (down_interruptible(&port->sem))
196 return -ERESTARTSYS;
193 197
194 ++port->open_count; 198 ++port->open_count;
195 199
@@ -215,6 +219,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
215 goto bailout_module_put; 219 goto bailout_module_put;
216 } 220 }
217 221
222 up(&port->sem);
218 return 0; 223 return 0;
219 224
220bailout_module_put: 225bailout_module_put:
@@ -222,6 +227,7 @@ bailout_module_put:
222bailout_kref_put: 227bailout_kref_put:
223 kref_put(&serial->kref, destroy_serial); 228 kref_put(&serial->kref, destroy_serial);
224 port->open_count = 0; 229 port->open_count = 0;
230 up(&port->sem);
225 return retval; 231 return retval;
226} 232}
227 233
@@ -234,8 +240,10 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
234 240
235 dbg("%s - port %d", __FUNCTION__, port->number); 241 dbg("%s - port %d", __FUNCTION__, port->number);
236 242
243 down(&port->sem);
244
237 if (port->open_count == 0) 245 if (port->open_count == 0)
238 return; 246 goto out;
239 247
240 --port->open_count; 248 --port->open_count;
241 if (port->open_count == 0) { 249 if (port->open_count == 0) {
@@ -253,6 +261,9 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
253 } 261 }
254 262
255 kref_put(&port->serial->kref, destroy_serial); 263 kref_put(&port->serial->kref, destroy_serial);
264
265out:
266 up(&port->sem);
256} 267}
257 268
258static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count) 269static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count)
@@ -774,6 +785,7 @@ int usb_serial_probe(struct usb_interface *interface,
774 port->number = i + serial->minor; 785 port->number = i + serial->minor;
775 port->serial = serial; 786 port->serial = serial;
776 spin_lock_init(&port->lock); 787 spin_lock_init(&port->lock);
788 sema_init(&port->sem, 1);
777 INIT_WORK(&port->work, usb_serial_port_softint, port); 789 INIT_WORK(&port->work, usb_serial_port_softint, port);
778 serial->port[i] = port; 790 serial->port[i] = port;
779 } 791 }