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 0998d06310
(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>
This commit is contained in:
parent
acbf0e5263
commit
a8f2ae7a3a
|
@ -49,7 +49,8 @@
|
||||||
* Function prototypes
|
* Function prototypes
|
||||||
*/
|
*/
|
||||||
static int mct_u232_startup(struct usb_serial *serial);
|
static int mct_u232_startup(struct usb_serial *serial);
|
||||||
static void mct_u232_release(struct usb_serial *serial);
|
static int mct_u232_port_probe(struct usb_serial_port *port);
|
||||||
|
static int mct_u232_port_remove(struct usb_serial_port *remove);
|
||||||
static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port);
|
static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port);
|
||||||
static void mct_u232_close(struct usb_serial_port *port);
|
static void mct_u232_close(struct usb_serial_port *port);
|
||||||
static void mct_u232_dtr_rts(struct usb_serial_port *port, int on);
|
static void mct_u232_dtr_rts(struct usb_serial_port *port, int on);
|
||||||
|
@ -99,7 +100,8 @@ static struct usb_serial_driver mct_u232_device = {
|
||||||
.tiocmget = mct_u232_tiocmget,
|
.tiocmget = mct_u232_tiocmget,
|
||||||
.tiocmset = mct_u232_tiocmset,
|
.tiocmset = mct_u232_tiocmset,
|
||||||
.attach = mct_u232_startup,
|
.attach = mct_u232_startup,
|
||||||
.release = mct_u232_release,
|
.port_probe = mct_u232_port_probe,
|
||||||
|
.port_remove = mct_u232_port_remove,
|
||||||
.ioctl = mct_u232_ioctl,
|
.ioctl = mct_u232_ioctl,
|
||||||
.get_icount = mct_u232_get_icount,
|
.get_icount = mct_u232_get_icount,
|
||||||
};
|
};
|
||||||
|
@ -388,18 +390,8 @@ static void mct_u232_msr_to_state(struct usb_serial_port *port,
|
||||||
|
|
||||||
static int mct_u232_startup(struct usb_serial *serial)
|
static int mct_u232_startup(struct usb_serial *serial)
|
||||||
{
|
{
|
||||||
struct mct_u232_private *priv;
|
|
||||||
struct usb_serial_port *port, *rport;
|
struct usb_serial_port *port, *rport;
|
||||||
|
|
||||||
priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
|
|
||||||
if (!priv)
|
|
||||||
return -ENOMEM;
|
|
||||||
spin_lock_init(&priv->lock);
|
|
||||||
init_waitqueue_head(&priv->msr_wait);
|
|
||||||
usb_set_serial_port_data(serial->port[0], priv);
|
|
||||||
|
|
||||||
init_waitqueue_head(&serial->port[0]->write_wait);
|
|
||||||
|
|
||||||
/* Puh, that's dirty */
|
/* Puh, that's dirty */
|
||||||
port = serial->port[0];
|
port = serial->port[0];
|
||||||
rport = serial->port[1];
|
rport = serial->port[1];
|
||||||
|
@ -412,18 +404,31 @@ static int mct_u232_startup(struct usb_serial *serial)
|
||||||
return 0;
|
return 0;
|
||||||
} /* mct_u232_startup */
|
} /* mct_u232_startup */
|
||||||
|
|
||||||
|
static int mct_u232_port_probe(struct usb_serial_port *port)
|
||||||
static void mct_u232_release(struct usb_serial *serial)
|
|
||||||
{
|
{
|
||||||
struct mct_u232_private *priv;
|
struct mct_u232_private *priv;
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < serial->num_ports; ++i) {
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
||||||
/* My special items, the standard routines free my urbs */
|
if (!priv)
|
||||||
priv = usb_get_serial_port_data(serial->port[i]);
|
return -ENOMEM;
|
||||||
kfree(priv);
|
|
||||||
|
spin_lock_init(&priv->lock);
|
||||||
|
init_waitqueue_head(&priv->msr_wait);
|
||||||
|
|
||||||
|
usb_set_serial_port_data(port, priv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mct_u232_port_remove(struct usb_serial_port *port)
|
||||||
|
{
|
||||||
|
struct mct_u232_private *priv;
|
||||||
|
|
||||||
|
priv = usb_get_serial_port_data(port);
|
||||||
|
kfree(priv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
} /* mct_u232_release */
|
|
||||||
|
|
||||||
static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port)
|
static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue