[PATCH 07/16] USB: opticon: simplify bulk-in discovery in attach

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Remove custom end-point iteration which has already been taken care of
by usb-serial core.

The first bulk-in endpoint found will be associated with the first port.

Signed-off-by: Johan Hovold <jhovold@xxxxxxxxx>
---
 drivers/usb/serial/opticon.c | 49 +++++++++++++++-----------------------------
 1 file changed, 16 insertions(+), 33 deletions(-)

diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index a515c5f..e275abb 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -471,10 +471,12 @@ static int opticon_ioctl(struct tty_struct *tty,
 static int opticon_startup(struct usb_serial *serial)
 {
 	struct opticon_private *priv;
-	struct usb_host_interface *intf;
-	int i;
 	int retval = -ENOMEM;
-	bool bulk_in_found = false;
+
+	if (!serial->num_bulk_in) {
+		dev_err(&serial->dev->dev, "no bulk in endpoint\n");
+		return -ENODEV;
+	}
 
 	/* create our private serial structure */
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
@@ -485,40 +487,21 @@ static int opticon_startup(struct usb_serial *serial)
 	spin_lock_init(&priv->lock);
 	priv->port = serial->port[0];
 
-	/* find our bulk endpoint */
-	intf = serial->interface->altsetting;
-	for (i = 0; i < intf->desc.bNumEndpoints; ++i) {
-		struct usb_endpoint_descriptor *endpoint;
-
-		endpoint = &intf->endpoint[i].desc;
-		if (!usb_endpoint_is_bulk_in(endpoint))
-			continue;
-
-		priv->bulk_read_urb = usb_alloc_urb(0, GFP_KERNEL);
-		if (!priv->bulk_read_urb) {
-			dev_err(&serial->dev->dev, "out of memory\n");
-			goto error;
-		}
-
-		priv->buffer_size = usb_endpoint_maxp(endpoint) * 2;
-		priv->bulk_in_buffer = kmalloc(priv->buffer_size, GFP_KERNEL);
-		if (!priv->bulk_in_buffer) {
-			dev_err(&serial->dev->dev, "out of memory\n");
-			goto error;
-		}
-
-		priv->bulk_address = endpoint->bEndpointAddress;
-
-		bulk_in_found = true;
-		break;
-		}
+	priv->bulk_read_urb = usb_alloc_urb(0, GFP_KERNEL);
+	if (!priv->bulk_read_urb) {
+		dev_err(&serial->dev->dev, "out of memory\n");
+		goto error;
+	}
 
-	if (!bulk_in_found) {
-		dev_err(&serial->dev->dev,
-			"Error - the proper endpoints were not found!\n");
+	priv->buffer_size = 2 * priv->port->bulk_in_size;
+	priv->bulk_in_buffer = kmalloc(priv->buffer_size, GFP_KERNEL);
+	if (!priv->bulk_in_buffer) {
+		dev_err(&serial->dev->dev, "out of memory\n");
 		goto error;
 	}
 
+	priv->bulk_address = priv->port->bulk_in_endpointAddress;
+
 	usb_fill_bulk_urb(priv->bulk_read_urb, serial->dev,
 				usb_rcvbulkpipe(serial->dev,
 						priv->bulk_address),
-- 
1.7.12.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux