Skip to content

Commit cf4c9d2

Browse files
Yang Yingliangstorulf
authored andcommitted
mmc: mmc_spi: fix error handling in mmc_spi_probe()
If mmc_add_host() fails, it doesn't need to call mmc_remove_host(), or it will cause null-ptr-deref, because of deleting a not added device in mmc_remove_host(). To fix this, goto label 'fail_glue_init', if mmc_add_host() fails, and change the label 'fail_add_host' to 'fail_gpiod_request'. Fixes: 15a0580 ("mmc_spi host driver") Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Cc:stable@vger.kernel.org Link: https://lore.kernel.org/r/20230131013835.3564011-1-yangyingliang@huawei.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 605d9fb commit cf4c9d2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/mmc/host/mmc_spi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,15 +1437,15 @@ static int mmc_spi_probe(struct spi_device *spi)
14371437

14381438
status = mmc_add_host(mmc);
14391439
if (status != 0)
1440-
goto fail_add_host;
1440+
goto fail_glue_init;
14411441

14421442
/*
14431443
* Index 0 is card detect
14441444
* Old boardfiles were specifying 1 ms as debounce
14451445
*/
14461446
status = mmc_gpiod_request_cd(mmc, NULL, 0, false, 1000);
14471447
if (status == -EPROBE_DEFER)
1448-
goto fail_add_host;
1448+
goto fail_gpiod_request;
14491449
if (!status) {
14501450
/*
14511451
* The platform has a CD GPIO signal that may support
@@ -1460,7 +1460,7 @@ static int mmc_spi_probe(struct spi_device *spi)
14601460
/* Index 1 is write protect/read only */
14611461
status = mmc_gpiod_request_ro(mmc, NULL, 1, 0);
14621462
if (status == -EPROBE_DEFER)
1463-
goto fail_add_host;
1463+
goto fail_gpiod_request;
14641464
if (!status)
14651465
has_ro = true;
14661466

@@ -1474,7 +1474,7 @@ static int mmc_spi_probe(struct spi_device *spi)
14741474
? ", cd polling" : "");
14751475
return 0;
14761476

1477-
fail_add_host:
1477+
fail_gpiod_request:
14781478
mmc_remove_host(mmc);
14791479
fail_glue_init:
14801480
mmc_spi_dma_free(host);

0 commit comments

Comments
 (0)