Bug 37592

Summary: (ath5k) sc->ah is allocated in ath5k_init_softc() but is not freed
Product: Drivers Reporter: Tsyvarev Andrey (tsyvarev)
Component: network-wirelessAssignee: drivers_network-wireless (drivers_network-wireless)
Status: CLOSED CODE_FIX    
Severity: normal CC: alan, eugene.shatokhin, florian, linville
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.38.3 Subsystem:
Regression: No Bisected commit-id:

Description Tsyvarev Andrey 2011-06-16 07:10:47 UTC
Memory for "ah" field of "sc" structure is allocated via kzalloc() in ath5k_init_softc(). This function is called when driver is loaded and some wireless point is found (automatically) by the device. But it seems from the code that this memory is never freed after - there is no corresponded kfree for this field except error-path of ath5k_init_softc() itself.

Dynamic memory leaks detector from KEDR (http://kedr.berlios.de/) reports about leaks from that allocation in case of simple use case: loading driver, waiting several seconds, unloading driver.
Following freeing of block reported as leakage has not led to kernel failures - it seems that driver will not free allocated block neither directly nor indirectly. (This freeing was made with the kernel module designed by hand specially for that purpose.)
Comment 1 Tsyvarev Andrey 2011-06-16 11:18:49 UTC
Here is the output of KEDR leak detector concerning this leaked memory block:

Block at 0xbe9dc000, size: 8192; stack trace of the allocation:
[<c0771d10>] ath5k_init_softc+0x132/0xf6f [ath5k]
[<c077667a>] cleanup_module+0x1e3/0x225 [ath5k]
[<81187904>] local_pci_probe+0x43/0x86
[<81188050>] pci_device_probe+0x4a/0x76
[<81238ce9>] driver_probe_device+0x94/0x134
[<81238dd1>] __driver_attach+0x48/0x64
[<81238475>] bus_for_each_dev+0x42/0x6c
[<81238b84>] driver_attach+0x19/0x1b
[<8123885e>] bus_add_driver+0x8a/0x1d4
[<81239047>] driver_register+0x8e/0xef
[<8118822d>] __pci_register_driver+0x3d/0x9a
Comment 2 John W. Linville 2011-06-17 21:10:31 UTC
http://marc.info/?l=linux-wireless&m=130834452117167&w=2
Comment 3 Florian Mickler 2011-08-08 08:23:46 UTC
A patch referencing this bug report has been merged in Linux v3.1-rc1:

commit 0e8d1602b223efcd4eaaa799314f5d7ad1742035
Author: John W. Linville <linville@tuxdriver.com>
Date:   Fri Jun 17 16:41:30 2011 -0400

    ath5k: free sc->ah in ath5k_deinit_softc