diff mbox series

[v3,3/3] mmc: sdio: fix possible memory leak in mmc_attach_sdio()

Message ID 20221109025142.1565445-4-yangyingliang@huawei.com
State New
Headers show
Series mmc: sdio: fixes some leaks | expand

Commit Message

Yang Yingliang Nov. 9, 2022, 2:51 a.m. UTC
If sdio_add_func() returns error in mmc_attach_sdio(),
sdio_remove_func() can not free the memory that allocated
in sdio_init_func(), because the sdio function is not
presented and won't call put_device().

To fix these leaks, make sdio_func_present() only control
whether device_del() needs to be called or not. Then,
put_device() is called to give up the reference which was
set in device_initialize(), the memory can be freed in
sdio_release_func().

Fixes: 3d10a1ba0d37 ("sdio: fix reference counting in sdio_remove_func()")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/mmc/core/sdio_bus.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 266639504a94..da561658bdae 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -377,11 +377,11 @@  int sdio_add_func(struct sdio_func *func)
  */
 void sdio_remove_func(struct sdio_func *func)
 {
-	of_node_put(func->dev.of_node);
-	if (!sdio_func_present(func))
-		return;
+	if (!sdio_func_present(func)) {
+		device_del(&func->dev);
+	}
 
-	device_del(&func->dev);
+	of_node_put(func->dev.of_node);
 	put_device(&func->dev);
 }