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

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

USB: serial: ports: add minor and port number



The usb_serial_port structure had the number field, which was the minor
number for the port, which almost no one really cared about.  They
really wanted the number of the port within the device, which you had to
subtract from the minor of the parent usb_serial_device structure.  To
clean this up, provide the real minor number of the port, and the number
of the port within the serial device separately, as these numbers might
not be related in the future.

Bonus is that this cleans up a lot of logic in the drivers, and saves
lines overall.

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>

--
 drivers/staging/serqt_usb2/serqt_usb2.c |   21 +++--------
 drivers/usb/serial/ark3116.c            |    2 -
 drivers/usb/serial/bus.c                |    6 +--
 drivers/usb/serial/console.c            |    2 -
 drivers/usb/serial/cp210x.c             |    2 -
 drivers/usb/serial/cypress_m8.c         |    4 +-
 drivers/usb/serial/digi_acceleport.c    |    6 ---
 drivers/usb/serial/f81232.c             |    5 +-
 drivers/usb/serial/garmin_gps.c         |    6 +--
 drivers/usb/serial/io_edgeport.c        |   58 ++++++++++++--------------------
 drivers/usb/serial/io_ti.c              |   21 ++++-------
 drivers/usb/serial/keyspan.c            |   29 +++++++---------
 drivers/usb/serial/metro-usb.c          |    4 +-
 drivers/usb/serial/mos7720.c            |   37 +++++++++-----------
 drivers/usb/serial/mos7840.c            |   52 +++++++++-------------------
 drivers/usb/serial/opticon.c            |    2 -
 drivers/usb/serial/pl2303.c             |    2 -
 drivers/usb/serial/quatech2.c           |    7 +--
 drivers/usb/serial/sierra.c             |    2 -
 drivers/usb/serial/ti_usb_3410_5052.c   |   10 ++---
 drivers/usb/serial/usb-serial.c         |    7 ++-
 drivers/usb/serial/usb_wwan.c           |    2 -
 drivers/usb/serial/whiteheat.c          |   20 +++++------
 include/linux/usb/serial.h              |    6 ++-
 24 files changed, 133 insertions(+), 180 deletions(-)
parent 141dc40e
Loading
Loading
Loading
Loading
+7 −14
Original line number Original line Diff line number Diff line
@@ -873,7 +873,7 @@ static int qt_open(struct tty_struct *tty,
	result = qt_get_device(serial, &port0->DeviceData);
	result = qt_get_device(serial, &port0->DeviceData);


	/* Port specific setups */
	/* Port specific setups */
	result = qt_open_channel(serial, port->number, &ChannelData);
	result = qt_open_channel(serial, port->port_number, &ChannelData);
	if (result < 0) {
	if (result < 0) {
		dev_dbg(&port->dev, "qt_open_channel failed\n");
		dev_dbg(&port->dev, "qt_open_channel failed\n");
		return result;
		return result;
@@ -888,7 +888,7 @@ static int qt_open(struct tty_struct *tty,
	    (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD);
	    (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD);


	/* Set Baud rate to default and turn off (default)flow control here */
	/* Set Baud rate to default and turn off (default)flow control here */
	result = qt_setuart(serial, port->number, DEFAULT_DIVISOR, DEFAULT_LCR);
	result = qt_setuart(serial, port->port_number, DEFAULT_DIVISOR, DEFAULT_LCR);
	if (result < 0) {
	if (result < 0) {
		dev_dbg(&port->dev, "qt_setuart failed\n");
		dev_dbg(&port->dev, "qt_setuart failed\n");
		return result;
		return result;
@@ -906,7 +906,6 @@ static int qt_open(struct tty_struct *tty,
			qt_submit_urb_from_open(serial, port);
			qt_submit_urb_from_open(serial, port);
	}
	}


	dev_dbg(&port->dev, "port number is %d\n", port->number);
	dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor);
	dev_dbg(&port->dev, "serial number is %d\n", port->serial->minor);
	dev_dbg(&port->dev,
	dev_dbg(&port->dev,
		"Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
		"Bulkin endpoint is %d\n", port->bulk_in_endpointAddress);
@@ -1022,14 +1021,11 @@ static void qt_close(struct usb_serial_port *port)
	/* Close uart channel */
	/* Close uart channel */
	status = qt_close_channel(serial, index);
	status = qt_close_channel(serial, index);
	if (status < 0)
	if (status < 0)
		dev_dbg(&port->dev,
		dev_dbg(&port->dev, "%s - qt_close_channel failed.\n", __func__);
			"%s - port %d qt_close_channel failed.\n",
			__func__, port->number);


	port0->open_ports--;
	port0->open_ports--;


	dev_dbg(&port->dev, "qt_num_open_ports in close%d:in port%d\n",
	dev_dbg(&port->dev, "qt_num_open_ports in close%d\n", port0->open_ports);
		port0->open_ports, port->number);


	if (port0->open_ports == 0) {
	if (port0->open_ports == 0) {
		if (serial->port[0]->interrupt_in_urb) {
		if (serial->port[0]->interrupt_in_urb) {
@@ -1169,8 +1165,7 @@ static int qt_ioctl(struct tty_struct *tty,
		return 0;
		return 0;
	}
	}


	dev_dbg(&port->dev, "%s -No ioctl for that one.  port = %d\n",
	dev_dbg(&port->dev, "%s -No ioctl for that one.\n", __func__);
		__func__, port->number);
	return -ENOIOCTLCMD;
	return -ENOIOCTLCMD;
}
}


@@ -1245,8 +1240,7 @@ static void qt_set_termios(struct tty_struct *tty,


	/* Now determine flow control */
	/* Now determine flow control */
	if (cflag & CRTSCTS) {
	if (cflag & CRTSCTS) {
		dev_dbg(&port->dev, "%s - Enabling HW flow control port %d\n",
		dev_dbg(&port->dev, "%s - Enabling HW flow control\n", __func__);
			__func__, port->number);


		/* Enable RTS/CTS flow control */
		/* Enable RTS/CTS flow control */
		status = BoxSetHW_FlowCtrl(port->serial, index, 1);
		status = BoxSetHW_FlowCtrl(port->serial, index, 1);
@@ -1258,8 +1252,7 @@ static void qt_set_termios(struct tty_struct *tty,
	} else {
	} else {
		/* Disable RTS/CTS flow control */
		/* Disable RTS/CTS flow control */
		dev_dbg(&port->dev,
		dev_dbg(&port->dev,
			"%s - disabling HW flow control port %d\n",
			"%s - disabling HW flow control\n", __func__);
			__func__, port->number);


		status = BoxSetHW_FlowCtrl(port->serial, index, 0);
		status = BoxSetHW_FlowCtrl(port->serial, index, 0);
		if (status < 0) {
		if (status < 0) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -414,7 +414,7 @@ static int ark3116_ioctl(struct tty_struct *tty,
		memset(&serstruct, 0, sizeof(serstruct));
		memset(&serstruct, 0, sizeof(serstruct));
		serstruct.type = PORT_16654;
		serstruct.type = PORT_16654;
		serstruct.line = port->serial->minor;
		serstruct.line = port->serial->minor;
		serstruct.port = port->number;
		serstruct.port = port->port_number;
		serstruct.custom_divisor = 0;
		serstruct.custom_divisor = 0;
		serstruct.baud_base = 460800;
		serstruct.baud_base = 460800;


+3 −3
Original line number Original line Diff line number Diff line
@@ -43,7 +43,7 @@ static ssize_t show_port_number(struct device *dev,
{
{
	struct usb_serial_port *port = to_usb_serial_port(dev);
	struct usb_serial_port *port = to_usb_serial_port(dev);


	return sprintf(buf, "%d\n", port->number - port->serial->minor);
	return sprintf(buf, "%d\n", port->port_number);
}
}


static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL);
static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL);
@@ -80,7 +80,7 @@ static int usb_serial_device_probe(struct device *dev)
		goto exit_with_autopm;
		goto exit_with_autopm;
	}
	}


	minor = port->number;
	minor = port->minor;
	tty_register_device(usb_serial_tty_driver, minor, dev);
	tty_register_device(usb_serial_tty_driver, minor, dev);
	dev_info(&port->serial->dev->dev,
	dev_info(&port->serial->dev->dev,
		 "%s converter now attached to ttyUSB%d\n",
		 "%s converter now attached to ttyUSB%d\n",
@@ -106,7 +106,7 @@ static int usb_serial_device_remove(struct device *dev)
	/* make sure suspend/resume doesn't race against port_remove */
	/* make sure suspend/resume doesn't race against port_remove */
	usb_autopm_get_interface(port->serial->interface);
	usb_autopm_get_interface(port->serial->interface);


	minor = port->number;
	minor = port->minor;
	tty_unregister_device(usb_serial_tty_driver, minor);
	tty_unregister_device(usb_serial_tty_driver, minor);


	device_remove_file(&port->dev, &dev_attr_port_number);
	device_remove_file(&port->dev, &dev_attr_port_number);
+1 −1
Original line number Original line Diff line number Diff line
@@ -210,7 +210,7 @@ static void usb_console_write(struct console *co,
	if (count == 0)
	if (count == 0)
		return;
		return;


	pr_debug("%s - port %d, %d byte(s)\n", __func__, port->number, count);
	pr_debug("%s - minor %d, %d byte(s)\n", __func__, port->minor, count);


	if (!port->port.console) {
	if (!port->port.console) {
		pr_debug("%s - port not opened\n", __func__);
		pr_debug("%s - port not opened\n", __func__);
+0 −2
Original line number Original line Diff line number Diff line
@@ -666,8 +666,6 @@ static void cp210x_set_termios(struct tty_struct *tty,
	unsigned int bits;
	unsigned int bits;
	unsigned int modem_ctl[4];
	unsigned int modem_ctl[4];


	dev_dbg(dev, "%s - port %d\n", __func__, port->number);

	if (!tty)
	if (!tty)
		return;
		return;


Loading