Commit a794499b authored by Johan Hovold's avatar Johan Hovold

USB: serial: add calc_num_ports callback to generic driver

Add a calc_num_ports callback to the generic driver and verify that the
device has the required endpoints there instead of in core.

Note that the generic driver num_ports field was never used.
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
parent 415d7b3a
...@@ -48,14 +48,28 @@ static int usb_serial_generic_probe(struct usb_serial *serial, ...@@ -48,14 +48,28 @@ static int usb_serial_generic_probe(struct usb_serial *serial,
return 0; return 0;
} }
struct usb_serial_driver usb_serial_generic_device = { static int usb_serial_generic_calc_num_ports(struct usb_serial *serial,
struct usb_serial_endpoints *epds)
{
struct device *dev = &serial->interface->dev;
int num_ports = epds->num_bulk_out;
if (num_ports == 0) {
dev_err(dev, "Generic device with no bulk out, not allowed.\n");
return -ENODEV;
}
return num_ports;
}
static struct usb_serial_driver usb_serial_generic_device = {
.driver = { .driver = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "generic", .name = "generic",
}, },
.id_table = generic_device_ids, .id_table = generic_device_ids,
.num_ports = 1,
.probe = usb_serial_generic_probe, .probe = usb_serial_generic_probe,
.calc_num_ports = usb_serial_generic_calc_num_ports,
.throttle = usb_serial_generic_throttle, .throttle = usb_serial_generic_throttle,
.unthrottle = usb_serial_generic_unthrottle, .unthrottle = usb_serial_generic_unthrottle,
.resume = usb_serial_generic_resume, .resume = usb_serial_generic_resume,
......
...@@ -850,27 +850,16 @@ static int usb_serial_probe(struct usb_interface *interface, ...@@ -850,27 +850,16 @@ static int usb_serial_probe(struct usb_interface *interface,
retval = -ENODEV; retval = -ENODEV;
goto err_free_epds; goto err_free_epds;
} }
#ifdef CONFIG_USB_SERIAL_GENERIC
if (type == &usb_serial_generic_device) {
num_ports = epds->num_bulk_out;
if (num_ports == 0) {
dev_err(ddev, "Generic device with no bulk out, not allowed.\n");
retval = -EIO;
goto err_free_epds;
}
}
#endif
if (!num_ports) {
/* if this device type has a calc_num_ports function, call it */
if (type->calc_num_ports) { if (type->calc_num_ports) {
retval = type->calc_num_ports(serial, epds); retval = type->calc_num_ports(serial, epds);
if (retval < 0) if (retval < 0)
goto err_free_epds; goto err_free_epds;
num_ports = retval; num_ports = retval;
} }
if (!num_ports) if (!num_ports)
num_ports = type->num_ports; num_ports = type->num_ports;
}
if (num_ports > MAX_NUM_PORTS) { if (num_ports > MAX_NUM_PORTS) {
dev_warn(ddev, "too many ports requested: %d\n", num_ports); dev_warn(ddev, "too many ports requested: %d\n", num_ports);
......
...@@ -379,7 +379,6 @@ extern void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port, ...@@ -379,7 +379,6 @@ extern void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
extern int usb_serial_bus_register(struct usb_serial_driver *device); extern int usb_serial_bus_register(struct usb_serial_driver *device);
extern void usb_serial_bus_deregister(struct usb_serial_driver *device); extern void usb_serial_bus_deregister(struct usb_serial_driver *device);
extern struct usb_serial_driver usb_serial_generic_device;
extern struct bus_type usb_serial_bus_type; extern struct bus_type usb_serial_bus_type;
extern struct tty_driver *usb_serial_tty_driver; extern struct tty_driver *usb_serial_tty_driver;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment