Re: dwc2: Memory leak in dwc2_gadget_init
Hi Grigor, > Grigor Tovmasyan hat am 9. April 2018 um > 18:42 geschrieben: > > > Hi Stefan, > > On 4/2/2018 12:59 PM, Stefan Wahren wrote: > > Hi Minas, > > > > i noticed that in opposite to all allocations in dwc2_gadget_init() the > > function dwc2_hsotg_ep_alloc_request() uses kzalloc. So in case > > usb_add_gadget_udc() would fail, the memory of the USB request would be > > leaked: > > > > Linux raspberrypi 4.16.0-rc7-next-20180327+ #2 SMP PREEMPT Sat Mar 31 > > 13:24:47 CEST 2018 armv6l GNU/Linux > > Sorry for late reply. > Could you please tell me which tool you use for checking memory leak? there is no additional tool required. Just enable the following settings in the kernel config: Kernel hacking ---> Memory Debugging ---> [*] Kernel memory leak detector (CONFIG_DEBUG_KMEMLEAK=y) (1400) Maximum kmemleak early log entries (CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=1400) The log entries depends on your system, these are the settings for an Raspberry Pi. The detector noticed only leaks that has been triggered AFTER 10 minutes. > I prepared the patch and wanted to check it. So in order to reproduce this issue you will need to make probing fail at the same point. Please follow this patch [1] and this bootlog [2] for more context. Thanks Stefan [1] - https://www.spinics.net/lists/linux-usb/msg167472.html [2] - https://storage.kernelci.org/next/master/next-20180409/arm/bcm2835_defconfig/lab-baylibre/boot-bcm2837-rpi-3-b.txt > > Thanks, > Grigor. > > > > > unreferenced object 0xd8703cc0 (size 64): > >comm "kworker/0:1", pid 18, jiffies 4294937977 (age 2780.490s) > >hex dump (first 32 bytes): > > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > >backtrace: > > [<09023b43>] kmemleak_alloc+0x78/0xc0 > > [<60182b94>] kmem_cache_alloc_trace+0x150/0x398 > > [] dwc2_hsotg_ep_alloc_request+0x34/0x58 > > [<401a2371>] dwc2_gadget_init+0x32c/0x3ec > > [<2b1d6850>] dwc2_driver_probe+0x320/0x418 > > [<765bc59d>] platform_drv_probe+0x60/0xac > > [<65e4f320>] driver_probe_device+0x2d4/0x46c > > [<57a8c266>] __device_attach_driver+0xb0/0x104 > > [<14964192>] bus_for_each_drv+0x98/0xa0 > > [<34c644b4>] __device_attach+0xb0/0x13c > > [] device_initial_probe+0x1c/0x20 > > [] bus_probe_device+0x38/0x94 > > [<550305ed>] deferred_probe_work_func+0x12c/0x14c > > [<681db7c3>] process_one_work+0x3c8/0x76c > > [<818bc895>] process_scheduled_works+0x38/0x3c > > [<0dd47435>] worker_thread+0x2c4/0x43c > > > > Best regards > > Stefan > > -- > > To unsubscribe from this list: send the line "unsubscribe linux-usb" in > > the body of a message to majord...@vger.kernel.org > > More majordomo info at > > https://urldefense.proofpoint.com/v2/url?u=http-3A__vger.kernel.org_majordomo-2Dinfo.html&d=DwICaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=K1ULVL1slpLXpMJJlAXSOxws4tRq0IkTBqxDkyW2hUQ&m=i65dP-5DLfIelHtOk6TiLygqXtfp5tcq2CKdocriNto&s=EijYUhFJlFmz34zKw20t_Hq5TQHZoWJIbNmjpj2H7N8&e= > > > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: dwc2: Memory leak in dwc2_gadget_init
Hi Stefan, On 4/2/2018 12:59 PM, Stefan Wahren wrote: > Hi Minas, > > i noticed that in opposite to all allocations in dwc2_gadget_init() the > function dwc2_hsotg_ep_alloc_request() uses kzalloc. So in case > usb_add_gadget_udc() would fail, the memory of the USB request would be > leaked: > > Linux raspberrypi 4.16.0-rc7-next-20180327+ #2 SMP PREEMPT Sat Mar 31 > 13:24:47 CEST 2018 armv6l GNU/Linux Sorry for late reply. Could you please tell me which tool you use for checking memory leak? I prepared the patch and wanted to check it. Thanks, Grigor. > > unreferenced object 0xd8703cc0 (size 64): >comm "kworker/0:1", pid 18, jiffies 4294937977 (age 2780.490s) >hex dump (first 32 bytes): > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >backtrace: > [<09023b43>] kmemleak_alloc+0x78/0xc0 > [<60182b94>] kmem_cache_alloc_trace+0x150/0x398 > [] dwc2_hsotg_ep_alloc_request+0x34/0x58 > [<401a2371>] dwc2_gadget_init+0x32c/0x3ec > [<2b1d6850>] dwc2_driver_probe+0x320/0x418 > [<765bc59d>] platform_drv_probe+0x60/0xac > [<65e4f320>] driver_probe_device+0x2d4/0x46c > [<57a8c266>] __device_attach_driver+0xb0/0x104 > [<14964192>] bus_for_each_drv+0x98/0xa0 > [<34c644b4>] __device_attach+0xb0/0x13c > [] device_initial_probe+0x1c/0x20 > [] bus_probe_device+0x38/0x94 > [<550305ed>] deferred_probe_work_func+0x12c/0x14c > [<681db7c3>] process_one_work+0x3c8/0x76c > [<818bc895>] process_scheduled_works+0x38/0x3c > [<0dd47435>] worker_thread+0x2c4/0x43c > > Best regards > Stefan > -- > To unsubscribe from this list: send the line "unsubscribe linux-usb" in > the body of a message to majord...@vger.kernel.org > More majordomo info at > https://urldefense.proofpoint.com/v2/url?u=http-3A__vger.kernel.org_majordomo-2Dinfo.html&d=DwICaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=K1ULVL1slpLXpMJJlAXSOxws4tRq0IkTBqxDkyW2hUQ&m=i65dP-5DLfIelHtOk6TiLygqXtfp5tcq2CKdocriNto&s=EijYUhFJlFmz34zKw20t_Hq5TQHZoWJIbNmjpj2H7N8&e= > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
dwc2: Memory leak in dwc2_gadget_init
Hi Minas, i noticed that in opposite to all allocations in dwc2_gadget_init() the function dwc2_hsotg_ep_alloc_request() uses kzalloc. So in case usb_add_gadget_udc() would fail, the memory of the USB request would be leaked: Linux raspberrypi 4.16.0-rc7-next-20180327+ #2 SMP PREEMPT Sat Mar 31 13:24:47 CEST 2018 armv6l GNU/Linux unreferenced object 0xd8703cc0 (size 64): comm "kworker/0:1", pid 18, jiffies 4294937977 (age 2780.490s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 backtrace: [<09023b43>] kmemleak_alloc+0x78/0xc0 [<60182b94>] kmem_cache_alloc_trace+0x150/0x398 [] dwc2_hsotg_ep_alloc_request+0x34/0x58 [<401a2371>] dwc2_gadget_init+0x32c/0x3ec [<2b1d6850>] dwc2_driver_probe+0x320/0x418 [<765bc59d>] platform_drv_probe+0x60/0xac [<65e4f320>] driver_probe_device+0x2d4/0x46c [<57a8c266>] __device_attach_driver+0xb0/0x104 [<14964192>] bus_for_each_drv+0x98/0xa0 [<34c644b4>] __device_attach+0xb0/0x13c [] device_initial_probe+0x1c/0x20 [] bus_probe_device+0x38/0x94 [<550305ed>] deferred_probe_work_func+0x12c/0x14c [<681db7c3>] process_one_work+0x3c8/0x76c [<818bc895>] process_scheduled_works+0x38/0x3c [<0dd47435>] worker_thread+0x2c4/0x43c Best regards Stefan -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html