* [PATCH] mmc: core: Fix OF node leak in mmc_add_card()
@ 2026-09-17 10:17 Wentao Liang
2026-09-28 16:06 ` Ulf Hansson
0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-17 10:17 UTC (permalink / raw)
To: hansg; +Cc: linux-kernel, linux-mmc, s.hauer, ulfh, Wentao Liang, stable
mmc_add_card() stores the OF node returned by
mmc_of_find_child_device() in card->dev.of_node before calling
device_add(). That node carries a reference which is normally
released in mmc_remove_card(), but only when the card has been
marked present. If device_add() fails, mmc_card_set_present() is
never reached and the cleanup of the failed attach cannot release
the node, so the reference is leaked.
Release the reference on the device_add() failure path.
Fixes: 25185f3f31c9 ("mmc: Add SDIO function devicetree subnode parsing")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/mmc/core/bus.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index be5cf338bdeb..4d862d9bab23 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -379,8 +379,11 @@ int mmc_add_card(struct mmc_card *card)
device_enable_async_suspend(&card->dev);
ret = device_add(&card->dev);
- if (ret)
+ if (ret) {
+ of_node_put(card->dev.of_node);
+ card->dev.of_node = NULL;
return ret;
+ }
mmc_card_set_present(card);
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mmc: core: Fix OF node leak in mmc_add_card()
2026-09-17 10:17 [PATCH] mmc: core: Fix OF node leak in mmc_add_card() Wentao Liang
@ 2026-09-28 16:06 ` Ulf Hansson
0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2026-09-28 16:06 UTC (permalink / raw)
To: Wentao Liang; +Cc: hansg, linux-kernel, linux-mmc, s.hauer, ulfh, stable
On Thu, Sep 17, 2026 at 12:18 PM Wentao Liang <vulab@iscas.ac.cn> wrote:
>
> mmc_add_card() stores the OF node returned by
> mmc_of_find_child_device() in card->dev.of_node before calling
> device_add(). That node carries a reference which is normally
> released in mmc_remove_card(), but only when the card has been
> marked present. If device_add() fails, mmc_card_set_present() is
> never reached and the cleanup of the failed attach cannot release
> the node, so the reference is leaked.
>
> Release the reference on the device_add() failure path.
>
> Fixes: 25185f3f31c9 ("mmc: Add SDIO function devicetree subnode parsing")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
We have already a commit that takes care of this ("08b54e16d547 mmc:
core: Fix OF node reference leak on card add failure")
Kind regards
Uffe
> ---
> drivers/mmc/core/bus.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
> index be5cf338bdeb..4d862d9bab23 100644
> --- a/drivers/mmc/core/bus.c
> +++ b/drivers/mmc/core/bus.c
> @@ -379,8 +379,11 @@ int mmc_add_card(struct mmc_card *card)
> device_enable_async_suspend(&card->dev);
>
> ret = device_add(&card->dev);
> - if (ret)
> + if (ret) {
> + of_node_put(card->dev.of_node);
> + card->dev.of_node = NULL;
> return ret;
> + }
>
> mmc_card_set_present(card);
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-28 16:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 10:17 [PATCH] mmc: core: Fix OF node leak in mmc_add_card() Wentao Liang
2026-09-28 16:06 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®