Skip to content

Commit

Permalink
USB: serial: make minor allocation dynamic
Browse files Browse the repository at this point in the history
This moves the allocation of minor device numbers from a static array to
be dynamic, using the idr interface.  This means that you could
potentially get "gaps" in a minor number range for a single USB serial
device with multiple ports, but all should still work properly.

We remove the 'minor' field from the usb_serial structure, as it no
longer makes any sense for it (use the field in the usb_serial_port
structure if you really want to know this number), and take the fact
that we were overloading a number in this field to determine if we had
initialized the minor numbers or not, and just use a flag variable
instead.

Note, we still have the limitation of 255 USB to serial devices in the
system, as that is all we are registering with the TTY layer at this
point in time.

Tested-by: Tobias Winter <tobias@linuxdingsda.de>
Reviewed-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Greg Kroah-Hartman committed Jun 17, 2013
1 parent 1508124 commit e5b1e20
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 99 deletions.
15 changes: 7 additions & 8 deletions drivers/staging/serqt_usb2/serqt_usb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ static int qt_open(struct tty_struct *tty,
qt_submit_urb_from_open(serial, port);
}

dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor);
dev_dbg(&port->dev, "minor number is %d\n", port->minor);
dev_dbg(&port->dev,
"Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
dev_dbg(&port->dev,
Expand Down Expand Up @@ -1002,7 +1002,7 @@ static void qt_close(struct usb_serial_port *port)
status = 0;

tty = tty_port_tty_get(&port->port);
index = tty->index - serial->minor;
index = port->port_number;

qt_port = qt_get_port_private(port);
port0 = qt_get_port_private(serial->port[0]);
Expand Down Expand Up @@ -1129,12 +1129,11 @@ static int qt_ioctl(struct tty_struct *tty,
{
struct usb_serial_port *port = tty->driver_data;
struct quatech_port *qt_port = qt_get_port_private(port);
struct usb_serial *serial = get_usb_serial(port, __func__);
unsigned int index;

dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd);

index = tty->index - serial->minor;
index = port->port_number;

if (cmd == TIOCMIWAIT) {
while (qt_port != NULL) {
Expand Down Expand Up @@ -1180,7 +1179,7 @@ static void qt_set_termios(struct tty_struct *tty,
int baud, divisor, remainder;
int status;

index = tty->index - port->serial->minor;
index = port->port_number;

switch (cflag & CSIZE) {
case CS5:
Expand Down Expand Up @@ -1296,7 +1295,7 @@ static void qt_break(struct tty_struct *tty, int break_state)
u16 index, onoff;
unsigned int result;

index = tty->index - serial->minor;
index = port->port_number;

qt_port = qt_get_port_private(port);

Expand Down Expand Up @@ -1325,7 +1324,7 @@ static inline int qt_real_tiocmget(struct tty_struct *tty,
int status;
unsigned int index;

index = tty->index - serial->minor;
index = port->port_number;
status =
BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, &mcr);
if (status >= 0) {
Expand Down Expand Up @@ -1364,7 +1363,7 @@ static inline int qt_real_tiocmset(struct tty_struct *tty,
int status;
unsigned int index;

index = tty->index - serial->minor;
index = port->port_number;
status =
BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, &mcr);
if (status < 0)
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/ark3116.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ static int ark3116_ioctl(struct tty_struct *tty,
/* XXX: Some of these values are probably wrong. */
memset(&serstruct, 0, sizeof(serstruct));
serstruct.type = PORT_16654;
serstruct.line = port->serial->minor;
serstruct.line = port->minor;
serstruct.port = port->port_number;
serstruct.custom_divisor = 0;
serstruct.baud_base = 460800;
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/serial/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ static int usb_console_setup(struct console *co, char *options)
* no need to check the index here: if the index is wrong, console
* code won't call us
*/
serial = usb_serial_get_by_index(co->index);
if (serial == NULL) {
port = usb_serial_port_get_by_minor(co->index);
if (port == NULL) {
/* no device is connected yet, sorry :( */
pr_err("No USB device connected to ttyUSB%i\n", co->index);
return -ENODEV;
}
serial = port->serial;

retval = usb_autopm_get_interface(serial->interface);
if (retval)
goto error_get_interface;

port = serial->port[co->index - serial->minor];
tty_port_tty_set(&port->port, NULL);

info->port = port;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/f81232.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static int f81232_ioctl(struct tty_struct *tty,
case TIOCGSERIAL:
memset(&ser, 0, sizeof ser);
ser.type = PORT_16654;
ser.line = port->serial->minor;
ser.line = port->minor;
ser.port = port->port_number;
ser.baud_base = 460800;

Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/io_edgeport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ static int get_serial_info(struct edgeport_port *edge_port,
memset(&tmp, 0, sizeof(tmp));

tmp.type = PORT_16550A;
tmp.line = edge_port->port->serial->minor;
tmp.line = edge_port->port->minor;
tmp.port = edge_port->port->port_number;
tmp.irq = 0;
tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/io_ti.c
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@ static int get_serial_info(struct edgeport_port *edge_port,
memset(&tmp, 0, sizeof(tmp));

tmp.type = PORT_16550A;
tmp.line = edge_port->port->serial->minor;
tmp.line = edge_port->port->minor;
tmp.port = edge_port->port->port_number;
tmp.irq = 0;
tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/mos7720.c
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ static int get_serial_info(struct moschip_port *mos7720_port,
memset(&tmp, 0, sizeof(tmp));

tmp.type = PORT_16550A;
tmp.line = mos7720_port->port->serial->minor;
tmp.line = mos7720_port->port->minor;
tmp.port = mos7720_port->port->port_number;
tmp.irq = 0;
tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
Expand Down
7 changes: 3 additions & 4 deletions drivers/usb/serial/mos7840.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
* structures were not set up at that time.) */

dev_dbg(&port->dev, "port number is %d\n", port->port_number);
dev_dbg(&port->dev, "minor number is %d\n", port->serial->minor);
dev_dbg(&port->dev, "minor number is %d\n", port->minor);
dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
dev_dbg(&port->dev, "BulkOut endpoint is %d\n", port->bulk_out_endpointAddress);
dev_dbg(&port->dev, "Interrupt endpoint is %d\n", port->interrupt_in_endpointAddress);
Expand Down Expand Up @@ -2068,7 +2068,7 @@ static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
memset(&tmp, 0, sizeof(tmp));

tmp.type = PORT_16550A;
tmp.line = mos7840_port->port->serial->minor;
tmp.line = mos7840_port->port->minor;
tmp.port = mos7840_port->port->port_number;
tmp.irq = 0;
tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
Expand Down Expand Up @@ -2246,9 +2246,8 @@ static int mos7840_port_probe(struct usb_serial_port *port)
* usb-serial.c:get_free_serial() and cannot therefore be used
* to index device instances */
mos7840_port->port_num = pnum + 1;
dev_dbg(&port->dev, "port->serial->minor = %d\n", port->serial->minor);
dev_dbg(&port->dev, "port->minor = %d\n", port->minor);
dev_dbg(&port->dev, "mos7840_port->port_num = %d\n", mos7840_port->port_num);
dev_dbg(&port->dev, "serial->minor = %d\n", serial->minor);

if (mos7840_port->port_num == 1) {
mos7840_port->SpRegOffset = 0x0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/opticon.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static int get_serial_info(struct usb_serial_port *port,

/* fake emulate a 16550 uart to make userspace code happy */
tmp.type = PORT_16550A;
tmp.line = port->serial->minor;
tmp.line = port->minor;
tmp.port = 0;
tmp.irq = 0;
tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/pl2303.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ static int pl2303_ioctl(struct tty_struct *tty,
case TIOCGSERIAL:
memset(&ser, 0, sizeof ser);
ser.type = PORT_16654;
ser.line = port->serial->minor;
ser.line = port->minor;
ser.port = port->port_number;
ser.baud_base = 460800;

Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/quatech2.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static int get_serial_info(struct usb_serial_port *port,
return -EFAULT;

memset(&tmp, 0, sizeof(tmp));
tmp.line = port->serial->minor;
tmp.line = port->minor;
tmp.port = 0;
tmp.irq = 0;
tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/ssu100.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ static int get_serial_info(struct usb_serial_port *port,
return -EFAULT;

memset(&tmp, 0, sizeof(tmp));
tmp.line = port->serial->minor;
tmp.line = port->minor;
tmp.port = 0;
tmp.irq = 0;
tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/serial/ti_usb_3410_5052.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ static int ti_get_serial_info(struct ti_port *tport,
memset(&ret_serial, 0, sizeof(ret_serial));

ret_serial.type = PORT_16550A;
ret_serial.line = port->serial->minor;
ret_serial.line = port->minor;
ret_serial.port = port->port_number;
ret_serial.flags = tport->tp_flags;
ret_serial.xmit_fifo_size = TI_WRITE_BUF_SIZE;
Expand Down
Loading

0 comments on commit e5b1e20

Please sign in to comment.