Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb-serial: show port number in sysfs

Some usb-serial devices (e.g. certain Edgeport models) have more than
one serial port on the same USB device/interface.

Currently the only way to distinguish these ports in userspace is by
their minor device number: the driver makes them consecutive and in
stable order.

However, for the purpose of stable naming with udev this is
insufficient: when udev handles the ADD event for one of the ports it
doesn't know what minor number the other one has.

To make stable naming easier, export the port number via sysfs.

Signed-off-by: Roman Kagan <rkagan@sw.ru>
Signed-off-by: Dmitry Guryanov <dimak@dgap.mipt.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Roman Kagan and committed by
Greg Kroah-Hartman
ce0d9325 fdf99c9e

+16
+16
drivers/usb/serial/bus.c
··· 36 36 return 0; 37 37 } 38 38 39 + static ssize_t show_port_number(struct device *dev, 40 + struct device_attribute *attr, char *buf) 41 + { 42 + struct usb_serial_port *port = to_usb_serial_port(dev); 43 + 44 + return sprintf(buf, "%d\n", port->number - port->serial->minor); 45 + } 46 + 47 + static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL); 48 + 39 49 static int usb_serial_device_probe (struct device *dev) 40 50 { 41 51 struct usb_serial_driver *driver; ··· 72 62 goto exit; 73 63 } 74 64 65 + retval = device_create_file(dev, &dev_attr_port_number); 66 + if (retval) 67 + goto exit; 68 + 75 69 minor = port->number; 76 70 tty_register_device (usb_serial_tty_driver, minor, dev); 77 71 dev_info(&port->serial->dev->dev, ··· 97 83 if (!port) { 98 84 return -ENODEV; 99 85 } 86 + 87 + device_remove_file(&port->dev, &dev_attr_port_number); 100 88 101 89 driver = port->serial->type; 102 90 if (driver->port_remove) {