aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2012-10-25 04:29:13 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-10-25 12:37:04 -0400
commita8f2ae7a3aa59079d7e7e1ddf5007f03532f458c (patch)
tree4f0a989c4f77bc95b58566c10ad19d994a0036ec /drivers/usb
parentacbf0e5263de563e25f7c104868e4490b9e72b13 (diff)
USB: mct_u232: 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. Note that the write waitqueue was initialised but never used. 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/mct_u232.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index f3947712e137..a8bce134ffba 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -49,7 +49,8 @@
49 * Function prototypes 49 * Function prototypes
50 */ 50 */
51static int mct_u232_startup(struct usb_serial *serial); 51static int mct_u232_startup(struct usb_serial *serial);
52static void mct_u232_release(struct usb_serial *serial); 52static int mct_u232_port_probe(struct usb_serial_port *port);
53static int mct_u232_port_remove(struct usb_serial_port *remove);
53static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port); 54static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port);
54static void mct_u232_close(struct usb_serial_port *port); 55static void mct_u232_close(struct usb_serial_port *port);
55static void mct_u232_dtr_rts(struct usb_serial_port *port, int on); 56static void mct_u232_dtr_rts(struct usb_serial_port *port, int on);
@@ -99,7 +100,8 @@ static struct usb_serial_driver mct_u232_device = {
99 .tiocmget = mct_u232_tiocmget, 100 .tiocmget = mct_u232_tiocmget,
100 .tiocmset = mct_u232_tiocmset, 101 .tiocmset = mct_u232_tiocmset,
101 .attach = mct_u232_startup, 102 .attach = mct_u232_startup,
102 .release = mct_u232_release, 103 .port_probe = mct_u232_port_probe,
104 .port_remove = mct_u232_port_remove,
103 .ioctl = mct_u232_ioctl, 105 .ioctl = mct_u232_ioctl,
104 .get_icount = mct_u232_get_icount, 106 .get_icount = mct_u232_get_icount,
105}; 107};
@@ -388,18 +390,8 @@ static void mct_u232_msr_to_state(struct usb_serial_port *port,
388 390
389static int mct_u232_startup(struct usb_serial *serial) 391static int mct_u232_startup(struct usb_serial *serial)
390{ 392{
391 struct mct_u232_private *priv;
392 struct usb_serial_port *port, *rport; 393 struct usb_serial_port *port, *rport;
393 394
394 priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
395 if (!priv)
396 return -ENOMEM;
397 spin_lock_init(&priv->lock);
398 init_waitqueue_head(&priv->msr_wait);
399 usb_set_serial_port_data(serial->port[0], priv);
400
401 init_waitqueue_head(&serial->port[0]->write_wait);
402
403 /* Puh, that's dirty */ 395 /* Puh, that's dirty */
404 port = serial->port[0]; 396 port = serial->port[0];
405 rport = serial->port[1]; 397 rport = serial->port[1];
@@ -412,18 +404,31 @@ static int mct_u232_startup(struct usb_serial *serial)
412 return 0; 404 return 0;
413} /* mct_u232_startup */ 405} /* mct_u232_startup */
414 406
407static int mct_u232_port_probe(struct usb_serial_port *port)
408{
409 struct mct_u232_private *priv;
410
411 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
412 if (!priv)
413 return -ENOMEM;
415 414
416static void mct_u232_release(struct usb_serial *serial) 415 spin_lock_init(&priv->lock);
416 init_waitqueue_head(&priv->msr_wait);
417
418 usb_set_serial_port_data(port, priv);
419
420 return 0;
421}
422
423static int mct_u232_port_remove(struct usb_serial_port *port)
417{ 424{
418 struct mct_u232_private *priv; 425 struct mct_u232_private *priv;
419 int i;
420 426
421 for (i = 0; i < serial->num_ports; ++i) { 427 priv = usb_get_serial_port_data(port);
422 /* My special items, the standard routines free my urbs */ 428 kfree(priv);
423 priv = usb_get_serial_port_data(serial->port[i]); 429
424 kfree(priv); 430 return 0;
425 } 431}
426} /* mct_u232_release */
427 432
428static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port) 433static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port)
429{ 434{