• Wang Hai's avatar
    libertas: Fix possible memory leak in probe and disconnect · 9692151e
    Wang Hai authored
    I got memory leak as follows when doing fault injection test:
    
    unreferenced object 0xffff88812c7d7400 (size 512):
      comm "kworker/6:1", pid 176, jiffies 4295003332 (age 822.830s)
      hex dump (first 32 bytes):
        00 68 1e 04 81 88 ff ff 01 00 00 00 00 00 00 00  .h..............
        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      backtrace:
        [<ffffffff8167939c>] slab_post_alloc_hook+0x9c/0x490
        [<ffffffff8167f627>] kmem_cache_alloc_trace+0x1f7/0x470
        [<ffffffffa02c9873>] if_usb_probe+0x63/0x446 [usb8xxx]
        [<ffffffffa022668a>] usb_probe_interface+0x1aa/0x3c0 [usbcore]
        [<ffffffff82b59630>] really_probe+0x190/0x480
        [<ffffffff82b59a19>] __driver_probe_device+0xf9/0x180
        [<ffffffff82b59af3>] driver_probe_device+0x53/0x130
        [<ffffffff82b5a075>] __device_attach_driver+0x105/0x130
        [<ffffffff82b55949>] bus_for_each_drv+0x129/0x190
        [<ffffffff82b593c9>] __device_attach+0x1c9/0x270
        [<ffffffff82b5a250>] device_initial_probe+0x20/0x30
        [<ffffffff82b579c2>] bus_probe_device+0x142/0x160
        [<ffffffff82b52e49>] device_add+0x829/0x1300
        [<ffffffffa02229b1>] usb_set_configuration+0xb01/0xcc0 [usbcore]
        [<ffffffffa0235c4e>] usb_generic_driver_probe+0x6e/0x90 [usbcore]
        [<ffffffffa022641f>] usb_probe_device+0x6f/0x130 [usbcore]
    
    cardp is missing being freed in the error handling path of the probe
    and the path of the disconnect, which will cause memory leak.
    
    This patch adds the missing kfree().
    
    Fixes: 876c9d3a ("[PATCH] Marvell Libertas 8388 802.11b/g USB driver")
    Reported-by: default avatarHulk Robot <hulkci@huawei.com>
    Signed-off-by: default avatarWang Hai <wanghai38@huawei.com>
    Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
    Link: https://lore.kernel.org/r/20211020120345.2016045-3-wanghai38@huawei.com
    9692151e
if_usb.c 25.3 KB