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 7/9] mmc: toshsd: fix return value check of mmc_add_host()
Date: Tue, 1 Nov 2022 14:30:21 +0800	[thread overview]
Message-ID: <20221101063023.1664968-8-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, free_irq() also needs be called.

Fixes: a5eb8bbd66cc ("mmc: add Toshiba PCI SD controller driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/mmc/host/toshsd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/toshsd.c b/drivers/mmc/host/toshsd.c
index 8d037c2071ab..497791ffada6 100644
--- a/drivers/mmc/host/toshsd.c
+++ b/drivers/mmc/host/toshsd.c
@@ -651,7 +651,9 @@ static int toshsd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (ret)
 		goto unmap;
 
-	mmc_add_host(mmc);
+	ret = mmc_add_host(mmc);
+	if (ret)
+		goto free_irq;
 
 	base = pci_resource_start(pdev, 0);
 	dev_dbg(&pdev->dev, "MMIO %pa, IRQ %d\n", &base, pdev->irq);
@@ -660,6 +662,8 @@ static int toshsd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	return 0;
 
+free_irq:
+	free_irq(pdev->irq, host);
 unmap:
 	pci_iounmap(pdev, host->ioaddr);
 release:
-- 
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 ` [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 ` Yang Yingliang [this message]
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-8-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.