]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
USB: serial: f81534: use calc_num_endpoints to verify endpoints
authorJohan Hovold <johan@kernel.org>
Thu, 16 Mar 2017 16:13:37 +0000 (17:13 +0100)
committerJohan Hovold <johan@kernel.org>
Tue, 28 Mar 2017 09:00:08 +0000 (11:00 +0200)
Simplify the endpoint sanity check by letting core verify that the
required endpoints are present and moving the max-packet check to
calc_num_ports.

Signed-off-by: Johan Hovold <johan@kernel.org>
drivers/usb/serial/f81534.c

index 385087c008ed6dc956d58312a46beca2dc2d2c0d..a4b1fea4453ebdb4bcda5cd89c7c497c89b2ba96 100644 (file)
@@ -614,12 +614,21 @@ static int f81534_find_config_idx(struct usb_serial *serial, u8 *index)
 static int f81534_calc_num_ports(struct usb_serial *serial,
                                        struct usb_serial_endpoints *epds)
 {
+       struct device *dev = &serial->interface->dev;
+       int size_bulk_in = usb_endpoint_maxp(epds->bulk_in[0]);
+       int size_bulk_out = usb_endpoint_maxp(epds->bulk_out[0]);
        u8 setting[F81534_CUSTOM_DATA_SIZE];
        u8 setting_idx;
        u8 num_port = 0;
        int status;
        size_t i;
 
+       if (size_bulk_out != F81534_WRITE_BUFFER_SIZE ||
+                       size_bulk_in != F81534_MAX_RECEIVE_BLOCK_SIZE) {
+               dev_err(dev, "unsupported endpoint max packet size\n");
+               return -ENODEV;
+       }
+
        /* Check had custom setting */
        status = f81534_find_config_idx(serial, &setting_idx);
        if (status) {
@@ -1115,49 +1124,6 @@ static int f81534_setup_ports(struct usb_serial *serial)
        return 0;
 }
 
-static int f81534_probe(struct usb_serial *serial,
-                                       const struct usb_device_id *id)
-{
-       struct usb_endpoint_descriptor *endpoint;
-       struct usb_host_interface *iface_desc;
-       struct device *dev;
-       int num_bulk_in = 0;
-       int num_bulk_out = 0;
-       int size_bulk_in = 0;
-       int size_bulk_out = 0;
-       int i;
-
-       dev = &serial->interface->dev;
-       iface_desc = serial->interface->cur_altsetting;
-
-       for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
-               endpoint = &iface_desc->endpoint[i].desc;
-
-               if (usb_endpoint_is_bulk_in(endpoint)) {
-                       ++num_bulk_in;
-                       size_bulk_in = usb_endpoint_maxp(endpoint);
-               }
-
-               if (usb_endpoint_is_bulk_out(endpoint)) {
-                       ++num_bulk_out;
-                       size_bulk_out = usb_endpoint_maxp(endpoint);
-               }
-       }
-
-       if (num_bulk_in != 1 || num_bulk_out != 1) {
-               dev_err(dev, "expected endpoints not found\n");
-               return -ENODEV;
-       }
-
-       if (size_bulk_out != F81534_WRITE_BUFFER_SIZE ||
-                       size_bulk_in != F81534_MAX_RECEIVE_BLOCK_SIZE) {
-               dev_err(dev, "unsupported endpoint max packet size\n");
-               return -ENODEV;
-       }
-
-       return 0;
-}
-
 static int f81534_attach(struct usb_serial *serial)
 {
        struct f81534_serial_private *serial_priv;
@@ -1381,12 +1347,13 @@ static struct usb_serial_driver f81534_device = {
        },
        .description =          DRIVER_DESC,
        .id_table =             f81534_id_table,
+       .num_bulk_in =          1,
+       .num_bulk_out =         1,
        .open =                 f81534_open,
        .close =                f81534_close,
        .write =                f81534_write,
        .tx_empty =             f81534_tx_empty,
        .calc_num_ports =       f81534_calc_num_ports,
-       .probe =                f81534_probe,
        .attach =               f81534_attach,
        .port_probe =           f81534_port_probe,
        .dtr_rts =              f81534_dtr_rts,