diff mbox series

[v2,1/3] mmc: sdio: fix of node refcount leak in sdio_add_func()

Message ID 20221102012533.1270876-2-yangyingliang@huawei.com (mailing list archive)
State Changes Requested
Headers show
Series mmc: sdio: fixes some leaks | expand

Commit Message

Yang Yingliang Nov. 2, 2022, 1:25 a.m. UTC
If device_add() returns error in sdio_add_func(), sdio function is not
presented, so the node refcount that hold in sdio_set_of_node() can not
be put in sdio_remove_func() which is called from error path. Fix this
by calling of_node_put() if device_add() fails.

Fixes: 25185f3f31c9 ("mmc: Add SDIO function devicetree subnode parsing")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/mmc/core/sdio_bus.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ulf Hansson Nov. 8, 2022, 4:04 p.m. UTC | #1
On Wed, 2 Nov 2022 at 02:27, Yang Yingliang <yangyingliang@huawei.com> wrote:
>
> If device_add() returns error in sdio_add_func(), sdio function is not
> presented, so the node refcount that hold in sdio_set_of_node() can not
> be put in sdio_remove_func() which is called from error path. Fix this
> by calling of_node_put() if device_add() fails.
>
> Fixes: 25185f3f31c9 ("mmc: Add SDIO function devicetree subnode parsing")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/mmc/core/sdio_bus.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
> index babf21a0adeb..b9308813a226 100644
> --- a/drivers/mmc/core/sdio_bus.c
> +++ b/drivers/mmc/core/sdio_bus.c
> @@ -365,6 +365,8 @@ int sdio_add_func(struct sdio_func *func)
>         ret = device_add(&func->dev);
>         if (ret == 0)
>                 sdio_func_set_present(func);
> +       else
> +               of_node_put(func->dev.of_node);

I think it would be better to change the sdio_remove_func() to manage
this. In principle sdio_func_present() should not make
sdio_remove_func() to return immediately, but rather just control
whether device_del() needs to be called or not.

>
>         return ret;
>  }


Kind regards
Uffe
diff mbox series

Patch

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index babf21a0adeb..b9308813a226 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -365,6 +365,8 @@  int sdio_add_func(struct sdio_func *func)
 	ret = device_add(&func->dev);
 	if (ret == 0)
 		sdio_func_set_present(func);
+	else
+		of_node_put(func->dev.of_node);
 
 	return ret;
 }