aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2012-10-17 07:34:58 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-10-17 16:47:58 -0400
commit003615302a16579531932576bcd9582ddeba9018 (patch)
treee0f5b3077907da583663d0228d03e89b0280ff5e /drivers/usb
parent94ab71ce288921490ca857e25ad174e1921b1e29 (diff)
USB: io_ti: fix port-data memory leak
Fix port-data memory leak by moving port data allocation and deallocation to port_probe and port_remove. Since commit 0998d0631001288 (device-core: Ensure drvdata = NULL when no driver is bound) the port private data is no longer freed at release as it is no longer accessible. Compile-only tested. Cc: <stable@vger.kernel.org> Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/serial/io_ti.c91
1 files changed, 45 insertions, 46 deletions
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index a2209cd45093..9ae65d679f02 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2532,12 +2532,7 @@ static void edge_break(struct tty_struct *tty, int break_state)
2532static int edge_startup(struct usb_serial *serial) 2532static int edge_startup(struct usb_serial *serial)
2533{ 2533{
2534 struct edgeport_serial *edge_serial; 2534 struct edgeport_serial *edge_serial;
2535 struct edgeport_port *edge_port;
2536 struct usb_device *dev;
2537 int status; 2535 int status;
2538 int i;
2539
2540 dev = serial->dev;
2541 2536
2542 /* create our private serial structure */ 2537 /* create our private serial structure */
2543 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); 2538 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
@@ -2555,40 +2550,7 @@ static int edge_startup(struct usb_serial *serial)
2555 return status; 2550 return status;
2556 } 2551 }
2557 2552
2558 /* set up our port private structures */
2559 for (i = 0; i < serial->num_ports; ++i) {
2560 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2561 if (edge_port == NULL) {
2562 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2563 __func__);
2564 goto cleanup;
2565 }
2566 spin_lock_init(&edge_port->ep_lock);
2567 if (kfifo_alloc(&edge_port->write_fifo, EDGE_OUT_BUF_SIZE,
2568 GFP_KERNEL)) {
2569 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2570 __func__);
2571 kfree(edge_port);
2572 goto cleanup;
2573 }
2574 edge_port->port = serial->port[i];
2575 edge_port->edge_serial = edge_serial;
2576 usb_set_serial_port_data(serial->port[i], edge_port);
2577 edge_port->bUartMode = default_uart_mode;
2578 }
2579
2580 return 0; 2553 return 0;
2581
2582cleanup:
2583 for (--i; i >= 0; --i) {
2584 edge_port = usb_get_serial_port_data(serial->port[i]);
2585 kfifo_free(&edge_port->write_fifo);
2586 kfree(edge_port);
2587 usb_set_serial_port_data(serial->port[i], NULL);
2588 }
2589 kfree(edge_serial);
2590 usb_set_serial_data(serial, NULL);
2591 return -ENOMEM;
2592} 2554}
2593 2555
2594static void edge_disconnect(struct usb_serial *serial) 2556static void edge_disconnect(struct usb_serial *serial)
@@ -2597,17 +2559,54 @@ static void edge_disconnect(struct usb_serial *serial)
2597 2559
2598static void edge_release(struct usb_serial *serial) 2560static void edge_release(struct usb_serial *serial)
2599{ 2561{
2600 int i; 2562 kfree(usb_get_serial_data(serial));
2563}
2564
2565static int edge_port_probe(struct usb_serial_port *port)
2566{
2601 struct edgeport_port *edge_port; 2567 struct edgeport_port *edge_port;
2568 int ret;
2602 2569
2603 for (i = 0; i < serial->num_ports; ++i) { 2570 edge_port = kzalloc(sizeof(*edge_port), GFP_KERNEL);
2604 edge_port = usb_get_serial_port_data(serial->port[i]); 2571 if (!edge_port)
2572 return -ENOMEM;
2573
2574 ret = kfifo_alloc(&edge_port->write_fifo, EDGE_OUT_BUF_SIZE,
2575 GFP_KERNEL);
2576 if (ret) {
2577 kfree(edge_port);
2578 return -ENOMEM;
2579 }
2580
2581 ret = edge_create_sysfs_attrs(port);
2582 if (ret) {
2605 kfifo_free(&edge_port->write_fifo); 2583 kfifo_free(&edge_port->write_fifo);
2606 kfree(edge_port); 2584 kfree(edge_port);
2585 return ret;
2607 } 2586 }
2608 kfree(usb_get_serial_data(serial)); 2587
2588 spin_lock_init(&edge_port->ep_lock);
2589 edge_port->port = port;
2590 edge_port->edge_serial = usb_get_serial_data(port->serial);
2591 edge_port->bUartMode = default_uart_mode;
2592
2593 usb_set_serial_port_data(port, edge_port);
2594
2595 return 0;
2609} 2596}
2610 2597
2598static int edge_port_remove(struct usb_serial_port *port)
2599{
2600 struct edgeport_port *edge_port;
2601
2602 edge_port = usb_get_serial_port_data(port);
2603
2604 edge_remove_sysfs_attrs(port);
2605 kfifo_free(&edge_port->write_fifo);
2606 kfree(edge_port);
2607
2608 return 0;
2609}
2611 2610
2612/* Sysfs Attributes */ 2611/* Sysfs Attributes */
2613 2612
@@ -2667,8 +2666,8 @@ static struct usb_serial_driver edgeport_1port_device = {
2667 .attach = edge_startup, 2666 .attach = edge_startup,
2668 .disconnect = edge_disconnect, 2667 .disconnect = edge_disconnect,
2669 .release = edge_release, 2668 .release = edge_release,
2670 .port_probe = edge_create_sysfs_attrs, 2669 .port_probe = edge_port_probe,
2671 .port_remove = edge_remove_sysfs_attrs, 2670 .port_remove = edge_port_remove,
2672 .ioctl = edge_ioctl, 2671 .ioctl = edge_ioctl,
2673 .set_termios = edge_set_termios, 2672 .set_termios = edge_set_termios,
2674 .tiocmget = edge_tiocmget, 2673 .tiocmget = edge_tiocmget,
@@ -2698,8 +2697,8 @@ static struct usb_serial_driver edgeport_2port_device = {
2698 .attach = edge_startup, 2697 .attach = edge_startup,
2699 .disconnect = edge_disconnect, 2698 .disconnect = edge_disconnect,
2700 .release = edge_release, 2699 .release = edge_release,
2701 .port_probe = edge_create_sysfs_attrs, 2700 .port_probe = edge_port_probe,
2702 .port_remove = edge_remove_sysfs_attrs, 2701 .port_remove = edge_port_remove,
2703 .ioctl = edge_ioctl, 2702 .ioctl = edge_ioctl,
2704 .set_termios = edge_set_termios, 2703 .set_termios = edge_set_termios,
2705 .tiocmget = edge_tiocmget, 2704 .tiocmget = edge_tiocmget,