diff options
Diffstat (limited to 'drivers/net/usb/dm9601.c')
-rw-r--r-- | drivers/net/usb/dm9601.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/drivers/net/usb/dm9601.c b/drivers/net/usb/dm9601.c index f7319d326912..78df2be8a728 100644 --- a/drivers/net/usb/dm9601.c +++ b/drivers/net/usb/dm9601.c | |||
@@ -55,12 +55,28 @@ | |||
55 | 55 | ||
56 | static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data) | 56 | static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data) |
57 | { | 57 | { |
58 | void *buf; | ||
59 | int err = -ENOMEM; | ||
60 | |||
58 | devdbg(dev, "dm_read() reg=0x%02x length=%d", reg, length); | 61 | devdbg(dev, "dm_read() reg=0x%02x length=%d", reg, length); |
59 | return usb_control_msg(dev->udev, | 62 | |
60 | usb_rcvctrlpipe(dev->udev, 0), | 63 | buf = kmalloc(length, GFP_KERNEL); |
61 | DM_READ_REGS, | 64 | if (!buf) |
62 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | 65 | goto out; |
63 | 0, reg, data, length, USB_CTRL_SET_TIMEOUT); | 66 | |
67 | err = usb_control_msg(dev->udev, | ||
68 | usb_rcvctrlpipe(dev->udev, 0), | ||
69 | DM_READ_REGS, | ||
70 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
71 | 0, reg, buf, length, USB_CTRL_SET_TIMEOUT); | ||
72 | if (err == length) | ||
73 | memcpy(data, buf, length); | ||
74 | else if (err >= 0) | ||
75 | err = -EINVAL; | ||
76 | kfree(buf); | ||
77 | |||
78 | out: | ||
79 | return err; | ||
64 | } | 80 | } |
65 | 81 | ||
66 | static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value) | 82 | static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value) |
@@ -70,12 +86,28 @@ static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value) | |||
70 | 86 | ||
71 | static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data) | 87 | static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data) |
72 | { | 88 | { |
89 | void *buf = NULL; | ||
90 | int err = -ENOMEM; | ||
91 | |||
73 | devdbg(dev, "dm_write() reg=0x%02x, length=%d", reg, length); | 92 | devdbg(dev, "dm_write() reg=0x%02x, length=%d", reg, length); |
74 | return usb_control_msg(dev->udev, | 93 | |
75 | usb_sndctrlpipe(dev->udev, 0), | 94 | if (data) { |
76 | DM_WRITE_REGS, | 95 | buf = kmalloc(length, GFP_KERNEL); |
77 | USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE, | 96 | if (!buf) |
78 | 0, reg, data, length, USB_CTRL_SET_TIMEOUT); | 97 | goto out; |
98 | memcpy(buf, data, length); | ||
99 | } | ||
100 | |||
101 | err = usb_control_msg(dev->udev, | ||
102 | usb_sndctrlpipe(dev->udev, 0), | ||
103 | DM_WRITE_REGS, | ||
104 | USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE, | ||
105 | 0, reg, buf, length, USB_CTRL_SET_TIMEOUT); | ||
106 | kfree(buf); | ||
107 | if (err >= 0 && err < length) | ||
108 | err = -EINVAL; | ||
109 | out: | ||
110 | return err; | ||
79 | } | 111 | } |
80 | 112 | ||
81 | static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value) | 113 | static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value) |