mmc: mmc_spi: fix error handling in mmc_spi_probe()
commit cf4c9d2ac1e42c7d18b921bec39486896645b714 upstream.
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: 15a0580ced
("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
30716d9f0f
commit
0b3edcb24b
@@ -1450,7 +1450,7 @@ static int mmc_spi_probe(struct spi_device *spi)
|
|||||||
|
|
||||||
status = mmc_add_host(mmc);
|
status = mmc_add_host(mmc);
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
goto fail_add_host;
|
goto fail_glue_init;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Index 0 is card detect
|
* Index 0 is card detect
|
||||||
@@ -1458,7 +1458,7 @@ static int mmc_spi_probe(struct spi_device *spi)
|
|||||||
*/
|
*/
|
||||||
status = mmc_gpiod_request_cd(mmc, NULL, 0, false, 1000);
|
status = mmc_gpiod_request_cd(mmc, NULL, 0, false, 1000);
|
||||||
if (status == -EPROBE_DEFER)
|
if (status == -EPROBE_DEFER)
|
||||||
goto fail_add_host;
|
goto fail_gpiod_request;
|
||||||
if (!status) {
|
if (!status) {
|
||||||
/*
|
/*
|
||||||
* The platform has a CD GPIO signal that may support
|
* The platform has a CD GPIO signal that may support
|
||||||
@@ -1473,7 +1473,7 @@ static int mmc_spi_probe(struct spi_device *spi)
|
|||||||
/* Index 1 is write protect/read only */
|
/* Index 1 is write protect/read only */
|
||||||
status = mmc_gpiod_request_ro(mmc, NULL, 1, 0);
|
status = mmc_gpiod_request_ro(mmc, NULL, 1, 0);
|
||||||
if (status == -EPROBE_DEFER)
|
if (status == -EPROBE_DEFER)
|
||||||
goto fail_add_host;
|
goto fail_gpiod_request;
|
||||||
if (!status)
|
if (!status)
|
||||||
has_ro = true;
|
has_ro = true;
|
||||||
|
|
||||||
@@ -1487,7 +1487,7 @@ static int mmc_spi_probe(struct spi_device *spi)
|
|||||||
? ", cd polling" : "");
|
? ", cd polling" : "");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail_add_host:
|
fail_gpiod_request:
|
||||||
mmc_remove_host(mmc);
|
mmc_remove_host(mmc);
|
||||||
fail_glue_init:
|
fail_glue_init:
|
||||||
mmc_spi_dma_free(host);
|
mmc_spi_dma_free(host);
|
||||||
|
Reference in New Issue
Block a user