* [PATCH v2] mmc: mmc_spi: fix error handling in mmc_spi_probe()
@ 2023-01-31 1:38 Yang Yingliang
2023-02-13 23:48 ` Ulf Hansson
0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2023-01-31 1:38 UTC (permalink / raw)
To: linux-mmc; +Cc: ulf.hansson, drzeus, david-b, CLoehle, yangyingliang
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: 15a0580ced08 ("mmc_spi host driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v1 -> v2:
Fix a typo.
---
drivers/mmc/host/mmc_spi.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 106dd204b1a7..cc333ad67cac 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1437,7 +1437,7 @@ static int mmc_spi_probe(struct spi_device *spi)
status = mmc_add_host(mmc);
if (status != 0)
- goto fail_add_host;
+ goto fail_glue_init;
/*
* Index 0 is card detect
@@ -1445,7 +1445,7 @@ static int mmc_spi_probe(struct spi_device *spi)
*/
status = mmc_gpiod_request_cd(mmc, NULL, 0, false, 1000);
if (status == -EPROBE_DEFER)
- goto fail_add_host;
+ goto fail_gpiod_request;
if (!status) {
/*
* The platform has a CD GPIO signal that may support
@@ -1460,7 +1460,7 @@ static int mmc_spi_probe(struct spi_device *spi)
/* Index 1 is write protect/read only */
status = mmc_gpiod_request_ro(mmc, NULL, 1, 0);
if (status == -EPROBE_DEFER)
- goto fail_add_host;
+ goto fail_gpiod_request;
if (!status)
has_ro = true;
@@ -1474,7 +1474,7 @@ static int mmc_spi_probe(struct spi_device *spi)
? ", cd polling" : "");
return 0;
-fail_add_host:
+fail_gpiod_request:
mmc_remove_host(mmc);
fail_glue_init:
mmc_spi_dma_free(host);
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mmc: mmc_spi: fix error handling in mmc_spi_probe()
2023-01-31 1:38 [PATCH v2] mmc: mmc_spi: fix error handling in mmc_spi_probe() Yang Yingliang
@ 2023-02-13 23:48 ` Ulf Hansson
0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2023-02-13 23:48 UTC (permalink / raw)
To: Yang Yingliang; +Cc: linux-mmc, drzeus, david-b, CLoehle
On Tue, 31 Jan 2023 at 02:38, Yang Yingliang <yangyingliang@huawei.com> wrote:
>
> 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: 15a0580ced08 ("mmc_spi host driver")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Applied for fixes and by adding a stable tag, thanks!
Kind regards
Uffe
> ---
> v1 -> v2:
> Fix a typo.
> ---
> drivers/mmc/host/mmc_spi.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
> index 106dd204b1a7..cc333ad67cac 100644
> --- a/drivers/mmc/host/mmc_spi.c
> +++ b/drivers/mmc/host/mmc_spi.c
> @@ -1437,7 +1437,7 @@ static int mmc_spi_probe(struct spi_device *spi)
>
> status = mmc_add_host(mmc);
> if (status != 0)
> - goto fail_add_host;
> + goto fail_glue_init;
>
> /*
> * Index 0 is card detect
> @@ -1445,7 +1445,7 @@ static int mmc_spi_probe(struct spi_device *spi)
> */
> status = mmc_gpiod_request_cd(mmc, NULL, 0, false, 1000);
> if (status == -EPROBE_DEFER)
> - goto fail_add_host;
> + goto fail_gpiod_request;
> if (!status) {
> /*
> * The platform has a CD GPIO signal that may support
> @@ -1460,7 +1460,7 @@ static int mmc_spi_probe(struct spi_device *spi)
> /* Index 1 is write protect/read only */
> status = mmc_gpiod_request_ro(mmc, NULL, 1, 0);
> if (status == -EPROBE_DEFER)
> - goto fail_add_host;
> + goto fail_gpiod_request;
> if (!status)
> has_ro = true;
>
> @@ -1474,7 +1474,7 @@ static int mmc_spi_probe(struct spi_device *spi)
> ? ", cd polling" : "");
> return 0;
>
> -fail_add_host:
> +fail_gpiod_request:
> mmc_remove_host(mmc);
> fail_glue_init:
> mmc_spi_dma_free(host);
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-13 23:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 1:38 [PATCH v2] mmc: mmc_spi: fix error handling in mmc_spi_probe() Yang Yingliang
2023-02-13 23:48 ` Ulf Hansson
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.