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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 sdio_remove_func() will return directly.

To fix these leaks, we can call put_device() to give up
the reference which was set in device_initialize(), then
the memory can be freed in sdio_release_func().

Fixes: 3d10a1ba0d37 ("sdio: fix reference counting in sdio_remove_func()")
Cc: Daniel Drake <drake@xxxxxxxxxxxxx>
Cc: Matt Fleming <matt@xxxxxxxxxxxxxxxxxxx>
Cc: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
---
 drivers/mmc/core/sdio_bus.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

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




[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux