All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: ftdi-elan: fix memory leak on device disconnect
@ 2021-12-17  8:34 Wei Yongjun
  2021-12-17  9:57 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2021-12-17  8:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Colin Ian King, Tony Olech
  Cc: Wei Yongjun, linux-usb, Hulk Robot

'ftdi' is alloced when probe device, but not free on device disconnect,
this cause a memory leak as follows:

unreferenced object 0xffff88800d584000 (size 8400):
  comm "kworker/0:2", pid 3809, jiffies 4295453055 (age 13.784s)
  hex dump (first 32 bytes):
    00 40 58 0d 80 88 ff ff 00 40 58 0d 80 88 ff ff  .@X......@X.....
    00 00 00 00 00 00 00 00 00 00 00 00 ad 4e ad de  .............N..
  backtrace:
    [<000000000d47f947>] kmalloc_order_trace+0x19/0x110 mm/slab_common.c:960
    [<000000008548ac68>] ftdi_elan_probe+0x8c/0x880 drivers/usb/misc/ftdi-elan.c:2647
    [<000000007f73e422>] usb_probe_interface+0x31b/0x800 drivers/usb/core/driver.c:396
    [<00000000fe8d07fc>] really_probe+0x299/0xc30 drivers/base/dd.c:517
    [<0000000005da7d32>] __driver_probe_device+0x357/0x500 drivers/base/dd.c:751
    [<000000003c2c9579>] driver_probe_device+0x4e/0x140 drivers/base/dd.c:781

Fix it by freeing 'ftdi' after nobody use it.

Fixes: a5c66e4b2418 ("USB: ftdi-elan: client driver for ELAN Uxxx adapters")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>

diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index e5a8fcdbb78e..6c38c62d29b2 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -202,6 +202,7 @@ static void ftdi_elan_delete(struct kref *kref)
 	mutex_unlock(&ftdi_module_lock);
 	kfree(ftdi->bulk_in_buffer);
 	ftdi->bulk_in_buffer = NULL;
+	kfree(ftdi);
 }
 
 static void ftdi_elan_put_kref(struct usb_ftdi *ftdi)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: ftdi-elan: fix memory leak on device disconnect
  2021-12-17  8:34 [PATCH] usb: ftdi-elan: fix memory leak on device disconnect Wei Yongjun
@ 2021-12-17  9:57 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2021-12-17  9:57 UTC (permalink / raw)
  To: Wei Yongjun; +Cc: Colin Ian King, Tony Olech, linux-usb, Hulk Robot

On Fri, Dec 17, 2021 at 04:34:28PM +0800, Wei Yongjun wrote:
> 'ftdi' is alloced when probe device, but not free on device disconnect,
> this cause a memory leak as follows:
> 
> unreferenced object 0xffff88800d584000 (size 8400):
>   comm "kworker/0:2", pid 3809, jiffies 4295453055 (age 13.784s)
>   hex dump (first 32 bytes):
>     00 40 58 0d 80 88 ff ff 00 40 58 0d 80 88 ff ff  .@X......@X.....
>     00 00 00 00 00 00 00 00 00 00 00 00 ad 4e ad de  .............N..
>   backtrace:
>     [<000000000d47f947>] kmalloc_order_trace+0x19/0x110 mm/slab_common.c:960
>     [<000000008548ac68>] ftdi_elan_probe+0x8c/0x880 drivers/usb/misc/ftdi-elan.c:2647
>     [<000000007f73e422>] usb_probe_interface+0x31b/0x800 drivers/usb/core/driver.c:396
>     [<00000000fe8d07fc>] really_probe+0x299/0xc30 drivers/base/dd.c:517
>     [<0000000005da7d32>] __driver_probe_device+0x357/0x500 drivers/base/dd.c:751
>     [<000000003c2c9579>] driver_probe_device+0x4e/0x140 drivers/base/dd.c:781
> 
> Fix it by freeing 'ftdi' after nobody use it.
> 
> Fixes: a5c66e4b2418 ("USB: ftdi-elan: client driver for ELAN Uxxx adapters")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> 
> diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
> index e5a8fcdbb78e..6c38c62d29b2 100644
> --- a/drivers/usb/misc/ftdi-elan.c
> +++ b/drivers/usb/misc/ftdi-elan.c
> @@ -202,6 +202,7 @@ static void ftdi_elan_delete(struct kref *kref)
>  	mutex_unlock(&ftdi_module_lock);
>  	kfree(ftdi->bulk_in_buffer);
>  	ftdi->bulk_in_buffer = NULL;
> +	kfree(ftdi);
>  }

Wow, yes, good catch.  Funny no one has ever noticed that before :(

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-17  9:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17  8:34 [PATCH] usb: ftdi-elan: fix memory leak on device disconnect Wei Yongjun
2021-12-17  9:57 ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.