This is a note to let you know that I've just added the patch titled

    USB: kl5kusb105: fix port-data memory leak

to the 3.6-stable tree which can be found at:
    
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     usb-kl5kusb105-fix-port-data-memory-leak.patch
and it can be found in the queue-3.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <[email protected]> know about it.


>From 99a6f73c495c420df826e5b267fb073fd6766fc3 Mon Sep 17 00:00:00 2001
From: Johan Hovold <[email protected]>
Date: Wed, 17 Oct 2012 13:35:01 +0200
Subject: USB: kl5kusb105: fix port-data memory leak

From: Johan Hovold <[email protected]>

commit 99a6f73c495c420df826e5b267fb073fd6766fc3 upstream.

Fix port-data memory leak by replacing attach and release with
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.

Note that the write waitqueue was initialised but never used.

Compile-only tested.

Signed-off-by: Johan Hovold <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 drivers/usb/serial/kl5kusb105.c |   68 ++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 43 deletions(-)

--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -62,8 +62,8 @@ static bool debug;
 /*
  * Function prototypes
  */
-static int  klsi_105_startup(struct usb_serial *serial);
-static void klsi_105_release(struct usb_serial *serial);
+static int klsi_105_port_probe(struct usb_serial_port *port);
+static int klsi_105_port_remove(struct usb_serial_port *port);
 static int  klsi_105_open(struct tty_struct *tty, struct usb_serial_port 
*port);
 static void klsi_105_close(struct usb_serial_port *port);
 static void klsi_105_set_termios(struct tty_struct *tty,
@@ -101,8 +101,8 @@ static struct usb_serial_driver kl5kusb1
        /*.break_ctl =          klsi_105_break_ctl,*/
        .tiocmget =             klsi_105_tiocmget,
        .tiocmset =             klsi_105_tiocmset,
-       .attach =               klsi_105_startup,
-       .release =              klsi_105_release,
+       .port_probe =           klsi_105_port_probe,
+       .port_remove =          klsi_105_port_remove,
        .throttle =             usb_serial_generic_throttle,
        .unthrottle =           usb_serial_generic_unthrottle,
        .process_read_urb =     klsi_105_process_read_urb,
@@ -225,58 +225,40 @@ static int klsi_105_get_line_state(struc
  * Driver's tty interface functions
  */
 
-static int klsi_105_startup(struct usb_serial *serial)
+static int klsi_105_port_probe(struct usb_serial_port *port)
 {
        struct klsi_105_private *priv;
-       int i;
 
-       /* check if we support the product id (see keyspan.c)
-        * FIXME
-        */
-
-       /* allocate the private data structure */
-       for (i = 0; i < serial->num_ports; i++) {
-               priv = kmalloc(sizeof(struct klsi_105_private),
-                                                  GFP_KERNEL);
-               if (!priv) {
-                       dbg("%skmalloc for klsi_105_private failed.", __func__);
-                       i--;
-                       goto err_cleanup;
-               }
-               /* set initial values for control structures */
-               priv->cfg.pktlen    = 5;
-               priv->cfg.baudrate  = kl5kusb105a_sio_b9600;
-               priv->cfg.databits  = kl5kusb105a_dtb_8;
-               priv->cfg.unknown1  = 0;
-               priv->cfg.unknown2  = 1;
+       priv = kmalloc(sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
 
-               priv->line_state    = 0;
+       /* set initial values for control structures */
+       priv->cfg.pktlen    = 5;
+       priv->cfg.baudrate  = kl5kusb105a_sio_b9600;
+       priv->cfg.databits  = kl5kusb105a_dtb_8;
+       priv->cfg.unknown1  = 0;
+       priv->cfg.unknown2  = 1;
 
-               usb_set_serial_port_data(serial->port[i], priv);
+       priv->line_state    = 0;
 
-               spin_lock_init(&priv->lock);
+       spin_lock_init(&priv->lock);
 
-               /* priv->termios is left uninitialized until port opening */
-               init_waitqueue_head(&serial->port[i]->write_wait);
-       }
+       /* priv->termios is left uninitialized until port opening */
 
-       return 0;
+       usb_set_serial_port_data(port, priv);
 
-err_cleanup:
-       for (; i >= 0; i--) {
-               priv = usb_get_serial_port_data(serial->port[i]);
-               kfree(priv);
-               usb_set_serial_port_data(serial->port[i], NULL);
-       }
-       return -ENOMEM;
+       return 0;
 }
 
-static void klsi_105_release(struct usb_serial *serial)
+static int klsi_105_port_remove(struct usb_serial_port *port)
 {
-       int i;
+       struct klsi_105_private *priv;
 
-       for (i = 0; i < serial->num_ports; ++i)
-               kfree(usb_get_serial_port_data(serial->port[i]));
+       priv = usb_get_serial_port_data(port);
+       kfree(priv);
+
+       return 0;
 }
 
 static int  klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)


Patches currently in stable-queue which might be from [email protected] are

queue-3.6/usb-io_ti-fix-sysfs-attribute-creation.patch
queue-3.6/usb-kobil_sct-fix-port-data-memory-leak.patch
queue-3.6/usb-iuu_phoenix-fix-port-data-memory-leak.patch
queue-3.6/usb-spcp8x5-fix-port-data-memory-leak.patch
queue-3.6/usb-f81232-fix-port-data-memory-leak.patch
queue-3.6/usb-cypress_m8-fix-port-data-memory-leak.patch
queue-3.6/usb-io_ti-fix-port-data-memory-leak.patch
queue-3.6/usb-cyberjack-fix-port-data-memory-leak.patch
queue-3.6/usb-ark3116-fix-null-pointer-dereference.patch
queue-3.6/usb-ti_usb_3410_5052-fix-port-data-memory-leak.patch
queue-3.6/usb-pl2303-fix-port-data-memory-leak.patch
queue-3.6/usb-iuu_phoenix-fix-sysfs-attribute-creation.patch
queue-3.6/usb-kl5kusb105-fix-port-data-memory-leak.patch
queue-3.6/usb-oti6858-fix-port-data-memory-leak.patch
queue-3.6/usb-cp210x-fix-port-data-memory-leak.patch
queue-3.6/usb-belkin_sa-fix-port-data-memory-leak.patch
queue-3.6/usb-ssu100-fix-port-data-memory-leak.patch
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to