Skip to content

Commit dce6d8f

Browse files
harperchenstorulf
authored andcommitted
mmc: sunplus: fix return value check of mmc_add_host()
mmc_add_host() may return error, if we ignore its return value, 1. the memory allocated in mmc_alloc_host() will be leaked 2. null-ptr-deref will happen when calling mmc_remove_host() in remove function spmmc_drv_remove() because deleting not added device. Fix this by checking the return value of mmc_add_host(). Moreover, I fixed the error handling path of spmmc_drv_probe() to clean up. Fixes: 4e268fe ("mmc: Add mmc driver for Sunplus SP7021") Cc: stable@vger.kernel.org Signed-off-by: Wei Chen <harperchen1110@gmail.com> Link: https://lore.kernel.org/r/20230622090233.188539-1-harperchen1110@gmail.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent d830354 commit dce6d8f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/mmc/host/sunplus-mmc.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ static int spmmc_drv_probe(struct platform_device *pdev)
902902

903903
ret = mmc_of_parse(mmc);
904904
if (ret)
905-
goto probe_free_host;
905+
goto clk_disable;
906906

907907
mmc->ops = &spmmc_ops;
908908
mmc->f_min = SPMMC_MIN_CLK;
@@ -911,7 +911,7 @@ static int spmmc_drv_probe(struct platform_device *pdev)
911911

912912
ret = mmc_regulator_get_supply(mmc);
913913
if (ret)
914-
goto probe_free_host;
914+
goto clk_disable;
915915

916916
if (!mmc->ocr_avail)
917917
mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
@@ -927,9 +927,17 @@ static int spmmc_drv_probe(struct platform_device *pdev)
927927
host->tuning_info.enable_tuning = 1;
928928
pm_runtime_set_active(&pdev->dev);
929929
pm_runtime_enable(&pdev->dev);
930-
mmc_add_host(mmc);
930+
ret = mmc_add_host(mmc);
931+
if (ret)
932+
goto pm_disable;
931933

932-
return ret;
934+
return 0;
935+
936+
pm_disable:
937+
pm_runtime_disable(&pdev->dev);
938+
939+
clk_disable:
940+
clk_disable_unprepare(host->clk);
933941

934942
probe_free_host:
935943
if (mmc)

0 commit comments

Comments
 (0)