Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: toshsd: fix return value check of mmc_add_host()

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>
Link: https://lore.kernel.org/r/20221101063023.1664968-8-yangyingliang@huawei.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Yang Yingliang and committed by
Ulf Hansson
f670744a fc38a5a1

+5 -1
+5 -1
drivers/mmc/host/toshsd.c
··· 651 651 if (ret) 652 652 goto unmap; 653 653 654 - mmc_add_host(mmc); 654 + ret = mmc_add_host(mmc); 655 + if (ret) 656 + goto free_irq; 655 657 656 658 base = pci_resource_start(pdev, 0); 657 659 dev_dbg(&pdev->dev, "MMIO %pa, IRQ %d\n", &base, pdev->irq); ··· 662 660 663 661 return 0; 664 662 663 + free_irq: 664 + free_irq(pdev->irq, host); 665 665 unmap: 666 666 pci_iounmap(pdev, host->ioaddr); 667 667 release: