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 4/9] mmc: pxamci: fix return value check of mmc_add_host()
Date: Tue, 1 Nov 2022 14:30:18 +0800	[thread overview]
Message-ID: <20221101063023.1664968-5-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(), besides, ->exit() need be called to uninit the pdata.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/mmc/host/pxamci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index e4003f6058eb..2a988f942b6c 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -763,7 +763,12 @@ static int pxamci_probe(struct platform_device *pdev)
 			dev_warn(dev, "gpio_ro and get_ro() both defined\n");
 	}
 
-	mmc_add_host(mmc);
+	ret = mmc_add_host(mmc);
+	if (ret) {
+		if (host->pdata && host->pdata->exit)
+			host->pdata->exit(dev, mmc);
+		goto out;
+	}
 
 	return 0;
 
-- 
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 ` [PATCH 2/9] mmc: moxart: " Yang Yingliang
2022-11-01  6:30 ` [PATCH 3/9] mmc: mxcmmc: " Yang Yingliang
2022-11-01  6:30 ` Yang Yingliang [this message]
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-5-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.