dm9601: Consolidate common parts of dm_write_*_async
authorPeter Korsgaard <jacmet@sunsite.dk>
Thu, 15 Nov 2007 10:10:12 +0000 (11:10 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2008 23:04:01 +0000 (15:04 -0800)
dm_write_async and dm_write_reg_async are almost identical.
Move common functionality to dm_write_async_helper (saves ~256b).

Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
drivers/net/usb/dm9601.c

index 1ffdd106f4c49a898f61f8a6d5be98da4c1a4d95..633a511d6cb671151aa7c62e8bbf796f828f09d5 100644 (file)
@@ -101,17 +101,16 @@ static void dm_write_async_callback(struct urb *urb)
        usb_free_urb(urb);
 }
 
-static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
+static void dm_write_async_helper(struct usbnet *dev, u8 reg, u8 value,
+                                 u16 length, void *data)
 {
        struct usb_ctrlrequest *req;
        struct urb *urb;
        int status;
 
-       devdbg(dev, "dm_write_async() reg=0x%02x length=%d", reg, length);
-
        urb = usb_alloc_urb(0, GFP_ATOMIC);
        if (!urb) {
-               deverr(dev, "Error allocating URB in dm_write_async!");
+               deverr(dev, "Error allocating URB in dm_write_async_helper!");
                return;
        }
 
@@ -123,8 +122,8 @@ static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
        }
 
        req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
-       req->bRequest = DM_WRITE_REGS;
-       req->wValue = 0;
+       req->bRequest = length ? DM_WRITE_REGS : DM_WRITE_REG;
+       req->wValue = cpu_to_le16(value);
        req->wIndex = cpu_to_le16(reg);
        req->wLength = cpu_to_le16(length);
 
@@ -142,45 +141,19 @@ static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
        }
 }
 
-static void dm_write_reg_async(struct usbnet *dev, u8 reg, u8 value)
+static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
 {
-       struct usb_ctrlrequest *req;
-       struct urb *urb;
-       int status;
+       devdbg(dev, "dm_write_async() reg=0x%02x length=%d", reg, length);
 
+       dm_write_async_helper(dev, reg, 0, length, data);
+}
+
+static void dm_write_reg_async(struct usbnet *dev, u8 reg, u8 value)
+{
        devdbg(dev, "dm_write_reg_async() reg=0x%02x value=0x%02x",
               reg, value);
 
-       urb = usb_alloc_urb(0, GFP_ATOMIC);
-       if (!urb) {
-               deverr(dev, "Error allocating URB in dm_write_async!");
-               return;
-       }
-
-       req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
-       if (!req) {
-               deverr(dev, "Failed to allocate memory for control request");
-               usb_free_urb(urb);
-               return;
-       }
-
-       req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
-       req->bRequest = DM_WRITE_REG;
-       req->wValue = cpu_to_le16(value);
-       req->wIndex = cpu_to_le16(reg);
-       req->wLength = 0;
-
-       usb_fill_control_urb(urb, dev->udev,
-                            usb_sndctrlpipe(dev->udev, 0),
-                            (void *)req, NULL, 0, dm_write_async_callback, req);
-
-       status = usb_submit_urb(urb, GFP_ATOMIC);
-       if (status < 0) {
-               deverr(dev, "Error submitting the control message: status=%d",
-                      status);
-               kfree(req);
-               usb_free_urb(urb);
-       }
+       dm_write_async_helper(dev, reg, value, 0, NULL);
 }
 
 static int dm_read_shared_word(struct usbnet *dev, int phy, u8 reg, u16 *value)