aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Neukum <oneukum@suse.de>2007-03-14 10:22:25 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-04-27 16:28:35 -0400
commitfe4b65ec9127a336eeaa503f878062d9e6f44591 (patch)
tree93083a02fd33b2e24f85cd622bd41dac3cb66116
parent7378c57a8d4cf36e2f2b389d96d0d85043bd1c17 (diff)
mos7720 update
this driver has an interesting way of handling ENOMEM: complain and ignore. If you decide to live with allocation failures, you must 1. guard against URBs without corresponding buffers 2. complete allocation failures 3. always test entries for NULL before you follow the pointers This patch does so. Signed-off-by: Oliver Neukum <oneukum@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/serial/mos7720.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 4538dc3f3fff..6ba87e6e28c3 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -333,6 +333,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
333 int response; 333 int response;
334 int port_number; 334 int port_number;
335 char data; 335 char data;
336 int allocated_urbs = 0;
336 int j; 337 int j;
337 338
338 serial = port->serial; 339 serial = port->serial;
@@ -365,10 +366,16 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
365 GFP_KERNEL); 366 GFP_KERNEL);
366 if (!urb->transfer_buffer) { 367 if (!urb->transfer_buffer) {
367 err("%s-out of memory for urb buffers.", __FUNCTION__); 368 err("%s-out of memory for urb buffers.", __FUNCTION__);
369 usb_free_urb(mos7720_port->write_urb_pool[j]);
370 mos7720_port->write_urb_pool[j] = NULL;
368 continue; 371 continue;
369 } 372 }
373 allocated_urbs++;
370 } 374 }
371 375
376 if (!allocated_urbs)
377 return -ENOMEM;
378
372 /* Initialize MCS7720 -- Write Init values to corresponding Registers 379 /* Initialize MCS7720 -- Write Init values to corresponding Registers
373 * 380 *
374 * Register Index 381 * Register Index
@@ -526,7 +533,7 @@ static int mos7720_chars_in_buffer(struct usb_serial_port *port)
526 } 533 }
527 534
528 for (i = 0; i < NUM_URBS; ++i) { 535 for (i = 0; i < NUM_URBS; ++i) {
529 if (mos7720_port->write_urb_pool[i]->status == -EINPROGRESS) 536 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status == -EINPROGRESS)
530 chars += URB_TRANSFER_BUFFER_SIZE; 537 chars += URB_TRANSFER_BUFFER_SIZE;
531 } 538 }
532 dbg("%s - returns %d", __FUNCTION__, chars); 539 dbg("%s - returns %d", __FUNCTION__, chars);
@@ -629,7 +636,7 @@ static int mos7720_write_room(struct usb_serial_port *port)
629 } 636 }
630 637
631 for (i = 0; i < NUM_URBS; ++i) { 638 for (i = 0; i < NUM_URBS; ++i) {
632 if (mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) 639 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS)
633 room += URB_TRANSFER_BUFFER_SIZE; 640 room += URB_TRANSFER_BUFFER_SIZE;
634 } 641 }
635 642
@@ -664,7 +671,7 @@ static int mos7720_write(struct usb_serial_port *port,
664 urb = NULL; 671 urb = NULL;
665 672
666 for (i = 0; i < NUM_URBS; ++i) { 673 for (i = 0; i < NUM_URBS; ++i) {
667 if (mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) { 674 if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) {
668 urb = mos7720_port->write_urb_pool[i]; 675 urb = mos7720_port->write_urb_pool[i];
669 dbg("URB:%d",i); 676 dbg("URB:%d",i);
670 break; 677 break;