Skip to content

Commit 028635d

Browse files
mothacehejhovold
authored andcommitted
USB: mxu11x0: fix memory leak on usb_serial private data
On nominal execution, private data allocated on port_probe and attach are never freed. Add port_remove and release callbacks to free them respectively. Signed-off-by: Mathieu OTHACEHE <[email protected]> Signed-off-by: Johan Hovold <[email protected]>
1 parent e03cdf2 commit 028635d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

drivers/usb/serial/mxu11x0.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,16 @@ static int mxu1_port_probe(struct usb_serial_port *port)
368368
return 0;
369369
}
370370

371+
static int mxu1_port_remove(struct usb_serial_port *port)
372+
{
373+
struct mxu1_port *mxport;
374+
375+
mxport = usb_get_serial_port_data(port);
376+
kfree(mxport);
377+
378+
return 0;
379+
}
380+
371381
static int mxu1_startup(struct usb_serial *serial)
372382
{
373383
struct mxu1_device *mxdev;
@@ -427,6 +437,14 @@ static int mxu1_startup(struct usb_serial *serial)
427437
return err;
428438
}
429439

440+
static void mxu1_release(struct usb_serial *serial)
441+
{
442+
struct mxu1_device *mxdev;
443+
444+
mxdev = usb_get_serial_data(serial);
445+
kfree(mxdev);
446+
}
447+
430448
static int mxu1_write_byte(struct usb_serial_port *port, u32 addr,
431449
u8 mask, u8 byte)
432450
{
@@ -957,7 +975,9 @@ static struct usb_serial_driver mxu11x0_device = {
957975
.id_table = mxu1_idtable,
958976
.num_ports = 1,
959977
.port_probe = mxu1_port_probe,
978+
.port_remove = mxu1_port_remove,
960979
.attach = mxu1_startup,
980+
.release = mxu1_release,
961981
.open = mxu1_open,
962982
.close = mxu1_close,
963983
.ioctl = mxu1_ioctl,

0 commit comments

Comments
 (0)