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 2/9] mmc: moxart: fix return value check of mmc_add_host()
Date: Tue, 1 Nov 2022 14:30:16 +0800	[thread overview]
Message-ID: <20221101063023.1664968-3-yangyingliang@huawei.com> (raw)
In-Reply-To: <20221101063023.1664968-1-yangyingliang@huawei.com>

mmc_add_host() may return error, if we ignore its return value, the memory
that allocated in mmc_alloc_host() will be leaked and it will lead a kernel
crash because of deleting not added device in the remove path.

So fix this by checking the return value and goto error path which will call
mmc_free_host().

Fixes: 1b66e94e6b99 ("mmc: moxart: Add MOXA ART SD/MMC driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/mmc/host/moxart-mmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c
index dfc3ffd5b1f8..52ed30f2d9f4 100644
--- a/drivers/mmc/host/moxart-mmc.c
+++ b/drivers/mmc/host/moxart-mmc.c
@@ -665,7 +665,9 @@ static int moxart_probe(struct platform_device *pdev)
 		goto out;
 
 	dev_set_drvdata(dev, mmc);
-	mmc_add_host(mmc);
+	ret = mmc_add_host(mmc);
+	if (ret)
+		goto out;
 
 	dev_dbg(dev, "IRQ=%d, FIFO is %d bytes\n", irq, host->fifo_width);
 
-- 
2.25.1


  parent reply	other threads:[~2022-11-01  6:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01  6:30 [PATCH 0/9] mmc: fix return value check of mmc_add_host() Yang Yingliang
2022-11-01  6:30 ` [PATCH 1/9] mmc: alcor: " Yang Yingliang
2022-11-01  6:30 ` Yang Yingliang [this message]
2022-11-01  6:30 ` [PATCH 3/9] mmc: mxcmmc: " Yang Yingliang
2022-11-01  6:30 ` [PATCH 4/9] mmc: pxamci: " Yang Yingliang
2022-11-01  6:30 ` [PATCH 5/9] mmc: rtsx_pci: " Yang Yingliang
2022-11-01  6:30 ` [PATCH 6/9] mmc: rtsx_usb_sdmmc: " Yang Yingliang
2022-11-01  6:30 ` [PATCH 7/9] mmc: toshsd: " Yang Yingliang
2022-11-01  6:30 ` [PATCH 8/9] mmc: vub300: " Yang Yingliang
2022-11-01  6:30 ` [PATCH 9/9] mmc: wmt-sdmmc: " Yang Yingliang
2022-11-08 16:05 ` [PATCH 0/9] mmc: " Ulf Hansson

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=20221101063023.1664968-3-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.