Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5b1e206 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

USB: serial: make minor allocation dynamic



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: default avatarTobias Winter <tobias@linuxdingsda.de>
Reviewed-by: default avatarJohan Hovold <jhovold@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1508124d
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -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,
@@ -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]);
@@ -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) {
@@ -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:
@@ -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);

@@ -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) {
@@ -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)
+1 −1
Original line number Diff line number Diff line
@@ -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;
+3 −3
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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;

+1 −1
Original line number Diff line number Diff line
@@ -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;
Loading