diff options
author | Tomoki Sekiyama <tomoki.sekiyama@gmail.com> | 2010-10-02 17:59:06 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-10-22 13:21:52 -0400 |
commit | e06ea97fa47611992a5a61058729cf8e83bf6fda (patch) | |
tree | 11f56ee7991106409bc6c4d51af1db567a758f84 /drivers/usb | |
parent | 1b62d2583963d5974974aa923214bada7aa7b5d1 (diff) |
USB: yurex: fix memory leak and corrupted messages
This fixes the memory leak on disconnecting the device.
In addition, it fixes some messages corrupted by incorrect encoding.
Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/misc/yurex.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c index 5f6443bc6142..719c6180b31f 100644 --- a/drivers/usb/misc/yurex.c +++ b/drivers/usb/misc/yurex.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #define CMD_PADDING 0xff | 37 | #define CMD_PADDING 0xff |
38 | 38 | ||
39 | #define YUREX_BUF_SIZE 8 | 39 | #define YUREX_BUF_SIZE 8 |
40 | #define YUREX_WRITE_TIMEOUT (HZ) | 40 | #define YUREX_WRITE_TIMEOUT (HZ*2) |
41 | 41 | ||
42 | /* table of devices that work with this driver */ | 42 | /* table of devices that work with this driver */ |
43 | static struct usb_device_id yurex_table[] = { | 43 | static struct usb_device_id yurex_table[] = { |
@@ -83,7 +83,7 @@ static void yurex_control_callback(struct urb *urb) | |||
83 | int status = urb->status; | 83 | int status = urb->status; |
84 | 84 | ||
85 | if (status) { | 85 | if (status) { |
86 | err("%s - control failed: %d¥n", __func__, status); | 86 | err("%s - control failed: %d\n", __func__, status); |
87 | wake_up_interruptible(&dev->waitq); | 87 | wake_up_interruptible(&dev->waitq); |
88 | return; | 88 | return; |
89 | } | 89 | } |
@@ -97,6 +97,16 @@ static void yurex_delete(struct kref *kref) | |||
97 | dbg("yurex_delete"); | 97 | dbg("yurex_delete"); |
98 | 98 | ||
99 | usb_put_dev(dev->udev); | 99 | usb_put_dev(dev->udev); |
100 | if (dev->cntl_urb) { | ||
101 | usb_kill_urb(dev->cntl_urb); | ||
102 | if (dev->cntl_req) | ||
103 | usb_free_coherent(dev->udev, YUREX_BUF_SIZE, | ||
104 | dev->cntl_req, dev->cntl_urb->setup_dma); | ||
105 | if (dev->cntl_buffer) | ||
106 | usb_free_coherent(dev->udev, YUREX_BUF_SIZE, | ||
107 | dev->cntl_buffer, dev->cntl_urb->transfer_dma); | ||
108 | usb_free_urb(dev->cntl_urb); | ||
109 | } | ||
100 | if (dev->urb) { | 110 | if (dev->urb) { |
101 | usb_kill_urb(dev->urb); | 111 | usb_kill_urb(dev->urb); |
102 | if (dev->int_buffer) | 112 | if (dev->int_buffer) |
@@ -253,7 +263,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_ | |||
253 | usb_sndctrlpipe(dev->udev, 0), | 263 | usb_sndctrlpipe(dev->udev, 0), |
254 | (void *)dev->cntl_req, dev->cntl_buffer, | 264 | (void *)dev->cntl_req, dev->cntl_buffer, |
255 | YUREX_BUF_SIZE, yurex_control_callback, dev); | 265 | YUREX_BUF_SIZE, yurex_control_callback, dev); |
256 | dev->cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 266 | dev->cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
257 | 267 | ||
258 | 268 | ||
259 | /* allocate interrupt URB */ | 269 | /* allocate interrupt URB */ |
@@ -276,6 +286,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_ | |||
276 | usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr), | 286 | usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr), |
277 | dev->int_buffer, YUREX_BUF_SIZE, yurex_interrupt, | 287 | dev->int_buffer, YUREX_BUF_SIZE, yurex_interrupt, |
278 | dev, 1); | 288 | dev, 1); |
289 | dev->cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
279 | if (usb_submit_urb(dev->urb, GFP_KERNEL)) { | 290 | if (usb_submit_urb(dev->urb, GFP_KERNEL)) { |
280 | retval = -EIO; | 291 | retval = -EIO; |
281 | err("Could not submitting URB"); | 292 | err("Could not submitting URB"); |
@@ -296,7 +307,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_ | |||
296 | dev->bbu = -1; | 307 | dev->bbu = -1; |
297 | 308 | ||
298 | dev_info(&interface->dev, | 309 | dev_info(&interface->dev, |
299 | "USB Yurex device now attached to Yurex-%d¥n", | 310 | "USB YUREX device now attached to Yurex #%d\n", |
300 | interface->minor); | 311 | interface->minor); |
301 | 312 | ||
302 | return 0; | 313 | return 0; |
@@ -331,7 +342,7 @@ static void yurex_disconnect(struct usb_interface *interface) | |||
331 | /* decrement our usage count */ | 342 | /* decrement our usage count */ |
332 | kref_put(&dev->kref, yurex_delete); | 343 | kref_put(&dev->kref, yurex_delete); |
333 | 344 | ||
334 | dev_info(&interface->dev, "USB Yurex #%d now disconnected", minor); | 345 | dev_info(&interface->dev, "USB YUREX #%d now disconnected\n", minor); |
335 | } | 346 | } |
336 | 347 | ||
337 | static struct usb_driver yurex_driver = { | 348 | static struct usb_driver yurex_driver = { |
@@ -417,7 +428,7 @@ static ssize_t yurex_read(struct file *file, char *buffer, size_t count, loff_t | |||
417 | } | 428 | } |
418 | 429 | ||
419 | spin_lock_irqsave(&dev->lock, flags); | 430 | spin_lock_irqsave(&dev->lock, flags); |
420 | bytes_read = snprintf(in_buffer, 20, "%lld¥n", dev->bbu); | 431 | bytes_read = snprintf(in_buffer, 20, "%lld\n", dev->bbu); |
421 | spin_unlock_irqrestore(&dev->lock, flags); | 432 | spin_unlock_irqrestore(&dev->lock, flags); |
422 | 433 | ||
423 | if (*ppos < bytes_read) { | 434 | if (*ppos < bytes_read) { |