All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-mmc@vger.kernel.org>
Cc: <ulf.hansson@linaro.org>, <yangyingliang@huawei.com>
Subject: [PATCH v2 1/3] mmc: sdio: fix of node refcount leak in sdio_add_func()
Date: Wed, 2 Nov 2022 09:25:31 +0800	[thread overview]
Message-ID: <20221102012533.1270876-2-yangyingliang@huawei.com> (raw)
In-Reply-To: <20221102012533.1270876-1-yangyingliang@huawei.com>

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);
 
 	return ret;
 }
-- 
2.25.1


  reply	other threads:[~2022-11-02  1:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02  1:25 [PATCH v2 0/3] mmc: sdio: fixes some leaks Yang Yingliang
2022-11-02  1:25 ` Yang Yingliang [this message]
2022-11-08 16:04   ` [PATCH v2 1/3] mmc: sdio: fix of node refcount leak in sdio_add_func() Ulf Hansson
2022-11-02  1:25 ` [PATCH v2 2/3] mmc: sdio: fix possible memory leak in sdio_init_func() Yang Yingliang
2022-11-02  1:25 ` [PATCH v2 3/3] mmc: sdio: fix possible memory leak in mmc_attach_sdio() Yang Yingliang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221102012533.1270876-2-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.