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.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index cfcfd5ab06ce..2a70563bbee1 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -26,6 +26,7 @@
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
+#include <linux/seq_file.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/list.h>
@@ -204,6 +205,11 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
goto bailout_kref_put;
}
+ if (port->serial->disconnected) {
+ retval = -ENODEV;
+ goto bailout_kref_put;
+ }
+
if (mutex_lock_interruptible(&port->mutex)) {
retval = -ERESTARTSYS;
goto bailout_kref_put;
@@ -416,57 +422,52 @@ static int serial_break(struct tty_struct *tty, int break_state)
return 0;
}
-static int serial_read_proc(char *page, char **start, off_t off, int count,
- int *eof, void *data)
+static int serial_proc_show(struct seq_file *m, void *v)
{
struct usb_serial *serial;
- int length = 0;
int i;
- off_t begin = 0;
char tmp[40];
dbg("%s", __func__);
- length += sprintf(page, "usbserinfo:1.0 driver:2.0\n");
- for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
+ seq_puts(m, "usbserinfo:1.0 driver:2.0\n");
+ for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
serial = usb_serial_get_by_index(i);
if (serial == NULL)
continue;
- length += sprintf(page+length, "%d:", i);
+ seq_printf(m, "%d:", i);
if (serial->type->driver.owner)
- length += sprintf(page+length, " module:%s",
+ seq_printf(m, " module:%s",
module_name(serial->type->driver.owner));
- length += sprintf(page+length, " name:\"%s\"",
+ seq_printf(m, " name:\"%s\"",
serial->type->description);
- length += sprintf(page+length, " vendor:%04x product:%04x",
+ seq_printf(m, " vendor:%04x product:%04x",
le16_to_cpu(serial->dev->descriptor.idVendor),
le16_to_cpu(serial->dev->descriptor.idProduct));
- length += sprintf(page+length, " num_ports:%d",
- serial->num_ports);
- length += sprintf(page+length, " port:%d",
- i - serial->minor + 1);
+ seq_printf(m, " num_ports:%d", serial->num_ports);
+ seq_printf(m, " port:%d", i - serial->minor + 1);
usb_make_path(serial->dev, tmp, sizeof(tmp));
- length += sprintf(page+length, " path:%s", tmp);
+ seq_printf(m, " path:%s", tmp);
- length += sprintf(page+length, "\n");
- if ((length + begin) > (off + count)) {
- usb_serial_put(serial);
- goto done;
- }
- if ((length + begin) < off) {
- begin += length;
- length = 0;
- }
+ seq_putc(m, '\n');
usb_serial_put(serial);
}
- *eof = 1;
-done:
- if (off >= (length + begin))
- return 0;
- *start = page + (off-begin);
- return (count < begin+length-off) ? count : begin+length-off;
+ return 0;
+}
+
+static int serial_proc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, serial_proc_show, NULL);
}
+static const struct file_operations serial_proc_fops = {
+ .owner = THIS_MODULE,
+ .open = serial_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
static int serial_tiocmget(struct tty_struct *tty, struct file *file)
{
struct usb_serial_port *port = tty->driver_data;
@@ -1067,6 +1068,8 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
struct usb_serial_port *port;
int i, r = 0;
+ serial->suspending = 1;
+
for (i = 0; i < serial->num_ports; ++i) {
port = serial->port[i];
if (port)
@@ -1083,10 +1086,15 @@ EXPORT_SYMBOL(usb_serial_suspend);
int usb_serial_resume(struct usb_interface *intf)
{
struct usb_serial *serial = usb_get_intfdata(intf);
+ int rv;
+ serial->suspending = 0;
if (serial->type->resume)
- return serial->type->resume(serial);
- return 0;
+ rv = serial->type->resume(serial);
+ else
+ rv = usb_serial_generic_resume(serial);
+
+ return rv;
}
EXPORT_SYMBOL(usb_serial_resume);
@@ -1101,9 +1109,9 @@ static const struct tty_operations serial_ops = {
.unthrottle = serial_unthrottle,
.break_ctl = serial_break,
.chars_in_buffer = serial_chars_in_buffer,
- .read_proc = serial_read_proc,
.tiocmget = serial_tiocmget,
.tiocmset = serial_tiocmset,
+ .proc_fops = &serial_proc_fops,
};
struct tty_driver *usb_serial_tty_driver;
@@ -1222,7 +1230,6 @@ static void fixup_generic(struct usb_serial_driver *device)
set_to_generic_if_null(device, read_bulk_callback);
set_to_generic_if_null(device, write_bulk_callback);
set_to_generic_if_null(device, shutdown);
- set_to_generic_if_null(device, resume);
}
int usb_serial_register(struct usb_serial_driver *driver)
@@ -1230,6 +1237,9 @@ int usb_serial_register(struct usb_serial_driver *driver)
/* must be called with BKL held */
int retval;
+ if (usb_disabled())
+ return -ENODEV;
+
fixup_generic(driver);
if (!driver->description)