[PATCH 4/7] USB: cdc-wdm: move out request initialization to probe()

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

 



No need to run the same commands over and over again when we
can do it once, except for the length which must be updated
on each write.

Collecting the request intializations in one place makes
the code easier to read.  And allows us to kill the "inum"
field, as that is now unused outside probe()

Signed-off-by: Bjørn Mork <bjorn@xxxxxxx>
---
I am going to stop with these "cleanups" which don't really change 
anything now.  But they were necessary to get rid of some
obfuscation which hid the real bugs.


 drivers/usb/class/cdc-wdm.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index c1b66a5..b76696b 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -80,7 +80,6 @@ struct wdm_device {
 
 	unsigned long		flags;
 	u16			bufsize;
-	__le16			inum;
 	int			reslength;
 	int			length;
 	int			read;
@@ -269,7 +268,6 @@ static ssize_t wdm_write
 	u8 *buf;
 	int rv = -EMSGSIZE, r, we;
 	struct wdm_device *desc = file->private_data;
-	struct usb_ctrlrequest *req;
 
 	if (count > desc->bufsize)
 		count = desc->bufsize;
@@ -325,25 +323,19 @@ static ssize_t wdm_write
 		goto out;
 	}
 
-	req = desc->orq;
+	desc->orq->wLength = cpu_to_le16(count);
 	usb_fill_control_urb(
 		desc->command,
 		interface_to_usbdev(desc->intf),
 		/* using common endpoint 0 */
 		usb_sndctrlpipe(interface_to_usbdev(desc->intf), 0),
-		(unsigned char *)req,
+		(unsigned char *)desc->orq,
 		buf,
 		count,
 		wdm_out_callback,
 		desc
 	);
 
-	req->bRequestType = (USB_DIR_OUT | USB_TYPE_CLASS |
-			     USB_RECIP_INTERFACE);
-	req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND;
-	req->wValue = 0;
-	req->wIndex = desc->inum;
-	req->wLength = cpu_to_le16(count);
 	set_bit(WDM_IN_USE, &desc->flags);
 
 	rv = usb_submit_urb(desc->command, GFP_KERNEL);
@@ -353,7 +345,7 @@ static ssize_t wdm_write
 		dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv);
 	} else {
 		dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d",
-			req->wIndex);
+			desc->orq->wIndex);
 	}
 out:
 	usb_autopm_put_interface(desc->intf);
@@ -607,6 +599,7 @@ static int wdm_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	u8 *buffer = intf->altsetting->extra;
 	int buflen = intf->altsetting->extralen;
 	u16 maxcom = WDM_DEFAULT_BUFSIZE;
+	__le16 inum;
 
 	if (!buffer)
 		goto out;
@@ -647,7 +640,7 @@ next_desc:
 	init_waitqueue_head(&desc->wait);
 	desc->bufsize = maxcom;
 	/* this will be expanded and needed in hardware endianness */
-	desc->inum = cpu_to_le16((u16)intf->cur_altsetting->desc.bInterfaceNumber);
+	inum = cpu_to_le16((u16)intf->cur_altsetting->desc.bInterfaceNumber);
 	desc->intf = intf;
 	INIT_WORK(&desc->rxwork, wdm_rxwork);
 
@@ -701,10 +694,16 @@ next_desc:
 		ep->bInterval
 	);
 
+	desc->orq->bRequestType = (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE);
+	desc->orq->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND;
+	desc->orq->wValue = 0;
+	desc->orq->wIndex = inum;
+	desc->orq->wLength = 0;
+
 	desc->irq->bRequestType = (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE);
 	desc->irq->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE;
 	desc->irq->wValue = 0;
-	desc->irq->wIndex = desc->inum;
+	desc->irq->wIndex = inum;
 	desc->irq->wLength = cpu_to_le16(desc->bufsize);
 
 	usb_fill_control_urb(
-- 
1.7.8.3

--
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