usbnet: dm9601: apply introduced usb command APIs

Acked-by: Oliver Neukum <oneukum@suse.de>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Ming Lei 2012-10-24 19:46:57 +00:00 committed by David S. Miller
parent 90b8b037f7
commit 24b1042c4e

View File

@ -56,27 +56,12 @@
static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data) static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data)
{ {
void *buf; int err;
int err = -ENOMEM; err = usbnet_read_cmd(dev, DM_READ_REGS,
netdev_dbg(dev->net, "dm_read() reg=0x%02x length=%d\n", reg, length);
buf = kmalloc(length, GFP_KERNEL);
if (!buf)
goto out;
err = usb_control_msg(dev->udev,
usb_rcvctrlpipe(dev->udev, 0),
DM_READ_REGS,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0, reg, buf, length, USB_CTRL_SET_TIMEOUT); 0, reg, data, length);
if (err == length) if(err != length && err >= 0)
memcpy(data, buf, length);
else if (err >= 0)
err = -EINVAL; err = -EINVAL;
kfree(buf);
out:
return err; return err;
} }
@ -87,91 +72,29 @@ static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value)
static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data) static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data)
{ {
void *buf = NULL; int err;
int err = -ENOMEM; err = usbnet_write_cmd(dev, DM_WRITE_REGS,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0, reg, data, length);
netdev_dbg(dev->net, "dm_write() reg=0x%02x, length=%d\n", reg, length);
if (data) {
buf = kmemdup(data, length, GFP_KERNEL);
if (!buf)
goto out;
}
err = usb_control_msg(dev->udev,
usb_sndctrlpipe(dev->udev, 0),
DM_WRITE_REGS,
USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
0, reg, buf, length, USB_CTRL_SET_TIMEOUT);
kfree(buf);
if (err >= 0 && err < length) if (err >= 0 && err < length)
err = -EINVAL; err = -EINVAL;
out:
return err; return err;
} }
static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value) static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value)
{ {
netdev_dbg(dev->net, "dm_write_reg() reg=0x%02x, value=0x%02x\n", return usbnet_write_cmd(dev, DM_WRITE_REGS,
reg, value); USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
return usb_control_msg(dev->udev, value, reg, NULL, 0);
usb_sndctrlpipe(dev->udev, 0),
DM_WRITE_REG,
USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE,
value, reg, NULL, 0, USB_CTRL_SET_TIMEOUT);
}
static void dm_write_async_callback(struct urb *urb)
{
struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
int status = urb->status;
if (status < 0)
printk(KERN_DEBUG "dm_write_async_callback() failed with %d\n",
status);
kfree(req);
usb_free_urb(urb);
} }
static void dm_write_async_helper(struct usbnet *dev, u8 reg, u8 value, static void dm_write_async_helper(struct usbnet *dev, u8 reg, u8 value,
u16 length, void *data) u16 length, void *data)
{ {
struct usb_ctrlrequest *req; usbnet_write_cmd_async(dev, DM_WRITE_REGS,
struct urb *urb; USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
int status; value, reg, data, length);
urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!urb) {
netdev_err(dev->net, "Error allocating URB in dm_write_async_helper!\n");
return;
}
req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
if (!req) {
netdev_err(dev->net, "Failed to allocate memory for control request\n");
usb_free_urb(urb);
return;
}
req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
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);
usb_fill_control_urb(urb, dev->udev,
usb_sndctrlpipe(dev->udev, 0),
(void *)req, data, length,
dm_write_async_callback, req);
status = usb_submit_urb(urb, GFP_ATOMIC);
if (status < 0) {
netdev_err(dev->net, "Error submitting the control message: status=%d\n",
status);
kfree(req);
usb_free_urb(urb);
}
} }
static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data) static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)