bcma: Fix memory leak for internally-handled cores
authorZenghui Yu <yuzenghui@huawei.com>
Tue, 27 Jul 2021 02:52:31 +0000 (10:52 +0800)
committerKalle Valo <kvalo@codeaurora.org>
Sun, 29 Aug 2021 11:44:57 +0000 (14:44 +0300)
commitb63aed3ff195130fef12e0af590f4838cf0201d8
tree83a21667fa4b292dc20cb3895e2a24f252b9f658
parentaee7c86a61c7b846ece6ee462a1145f2a209f24c
bcma: Fix memory leak for internally-handled cores

kmemleak reported that dev_name() of internally-handled cores were leaked
on driver unbinding. Let's use device_initialize() to take refcounts for
them and put_device() to properly free the related stuff.

While looking at it, there's another potential issue for those which should
be *registered* into driver core. If device_register() failed, we put
device once and freed bcma_device structures. In bcma_unregister_cores(),
they're treated as unregistered and we hit both UAF and double-free. That
smells not good and has also been fixed now.

Fixes: ab54bc8460b5 ("bcma: fill core details for every device")
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210727025232.663-2-yuzenghui@huawei.com
drivers/bcma/main.c