This is a note to let you know that I've just added the patch titled
USB: mos7720: 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-mos7720-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 4230af572f95b3115bba1ee6fb95681f3851ab26 Mon Sep 17 00:00:00 2001
From: Johan Hovold <[email protected]>
Date: Thu, 25 Oct 2012 10:29:05 +0200
Subject: USB: mos7720: fix port-data memory leak
From: Johan Hovold <[email protected]>
commit 4230af572f95b3115bba1ee6fb95681f3851ab26 upstream.
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 this patch also fixes a second port-data memory leak in the
error path of attach, should parallel-port initialisation fail.
Compile-only tested.
Signed-off-by: Johan Hovold <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/usb/serial/mos7720.c | 62 ++++++++++++++++++++++---------------------
1 file changed, 32 insertions(+), 30 deletions(-)
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -2023,9 +2023,7 @@ static int mos7720_ioctl(struct tty_stru
static int mos7720_startup(struct usb_serial *serial)
{
- struct moschip_port *mos7720_port;
struct usb_device *dev;
- int i;
char data;
u16 product;
int ret_val;
@@ -2063,29 +2061,6 @@ static int mos7720_startup(struct usb_se
serial->port[1]->interrupt_in_buffer = NULL;
}
-
- /* set up serial port private structures */
- for (i = 0; i < serial->num_ports; ++i) {
- mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
- if (mos7720_port == NULL) {
- dev_err(&dev->dev, "%s - Out of memory\n", __func__);
- return -ENOMEM;
- }
-
- /* Initialize all port interrupt end point to port 0 int
- * endpoint. Our device has only one interrupt endpoint
- * common to all ports */
- serial->port[i]->interrupt_in_endpointAddress =
- serial->port[0]->interrupt_in_endpointAddress;
-
- mos7720_port->port = serial->port[i];
- usb_set_serial_port_data(serial->port[i], mos7720_port);
-
- dbg("port number is %d", serial->port[i]->number);
- dbg("serial number is %d", serial->minor);
- }
-
-
/* setting configuration feature to one */
usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
(__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ);
@@ -2113,8 +2088,6 @@ static int mos7720_startup(struct usb_se
static void mos7720_release(struct usb_serial *serial)
{
- int i;
-
#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
/* close the parallel port */
@@ -2153,9 +2126,36 @@ static void mos7720_release(struct usb_s
kref_put(&mos_parport->ref_count, destroy_mos_parport);
}
#endif
- /* free private structure allocated for serial port */
- for (i = 0; i < serial->num_ports; ++i)
- kfree(usb_get_serial_port_data(serial->port[i]));
+}
+
+static int mos7720_port_probe(struct usb_serial_port *port)
+{
+ struct moschip_port *mos7720_port;
+
+ mos7720_port = kzalloc(sizeof(*mos7720_port), GFP_KERNEL);
+ if (!mos7720_port)
+ return -ENOMEM;
+
+ /* Initialize all port interrupt end point to port 0 int endpoint.
+ * Our device has only one interrupt endpoint common to all ports.
+ */
+ port->interrupt_in_endpointAddress =
+ port->serial->port[0]->interrupt_in_endpointAddress;
+ mos7720_port->port = port;
+
+ usb_set_serial_port_data(port, mos7720_port);
+
+ return 0;
+}
+
+static int mos7720_port_remove(struct usb_serial_port *port)
+{
+ struct moschip_port *mos7720_port;
+
+ mos7720_port = usb_get_serial_port_data(port);
+ kfree(mos7720_port);
+
+ return 0;
}
static struct usb_serial_driver moschip7720_2port_driver = {
@@ -2173,6 +2173,8 @@ static struct usb_serial_driver moschip7
.probe = mos77xx_probe,
.attach = mos7720_startup,
.release = mos7720_release,
+ .port_probe = mos7720_port_probe,
+ .port_remove = mos7720_port_remove,
.ioctl = mos7720_ioctl,
.tiocmget = mos7720_tiocmget,
.tiocmset = mos7720_tiocmset,
Patches currently in stable-queue which might be from [email protected] are
queue-3.6/usb-opticon-fix-memory-leak-in-error-path.patch
queue-3.6/usb-omninet-fix-port-data-memory-leak.patch
queue-3.6/usb-keyspan-fix-null-pointer-dereferences-and-memory-leaks.patch
queue-3.6/usb-quatech2-fix-io-after-disconnect.patch
queue-3.6/usb-mos7840-remove-null-urb-submission.patch
queue-3.6/usb-usb-wwan-fix-multiple-memory-leaks-in-error-paths.patch
queue-3.6/usb-mos7840-remove-invalid-disconnect-handling.patch
queue-3.6/usb-whiteheat-fix-memory-leak-in-error-path.patch
queue-3.6/usb-option-fix-interface-data-memory-leak-in-error-path.patch
queue-3.6/usb-metro-usb-fix-port-data-memory-leak.patch
queue-3.6/usb-mos7840-fix-port-device-leak-in-error-path.patch
queue-3.6/usb-mos7840-fix-urb-leak-at-release.patch
queue-3.6/usb-serial-fix-memory-leak-in-sierra_release.patch
queue-3.6/usb-ipw-fix-interface-data-memory-leak-in-error-path.patch
queue-3.6/usb-quatech2-fix-port-data-memory-leaks.patch
queue-3.6/usb-opticon-fix-dma-from-stack.patch
queue-3.6/usb-mct_u232-fix-port-data-memory-leak.patch
queue-3.6/usb-ch341-fix-port-data-memory-leak.patch
queue-3.6/usb-quatech2-fix-memory-leak-in-error-path.patch
queue-3.6/usb-qcserial-fix-interface-data-memory-leak-in-error-path.patch
queue-3.6/usb-sierra-fix-port-data-memory-leak.patch
queue-3.6/usb-whiteheat-fix-port-data-memory-leak.patch
queue-3.6/usb-metro-usb-fix-io-after-disconnect.patch
queue-3.6/usb-digi_acceleport-fix-port-data-memory-leak.patch
queue-3.6/usb-quatech2-fix-close-and-disconnect-urb-handling.patch
queue-3.6/usb-sierra-fix-memory-leak-in-probe-error-path.patch
queue-3.6/usb-mos7720-fix-port-data-memory-leak.patch
queue-3.6/usb-mct_u232-fix-broken-close.patch
queue-3.6/usb-sierra-fix-memory-leak-in-attach-error-path.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