diff mbox series

mmc: sdio: fix kernel panic when remove non-standard SDIO card

Message ID 20220927020158.1218469-1-ouyangweizhao@zeku.com
State Superseded
Headers show
Series mmc: sdio: fix kernel panic when remove non-standard SDIO card | expand

Commit Message

Weizhao Ouyang Sept. 27, 2022, 2:01 a.m. UTC
From: Matthew Ma <mahongwei@zeku.com>

SDIO tuple is only allocated for standard SDIO card, especially it
causes memory corruption issues when the non-standard SDIO card has
removed since the card device's reference counter does not increase for
it at sdio_init_func(), but all SDIO card device reference counter has
decreased at sdio_release_func().

Fixes: 1a632f8cdc33 ("sdio: split up common and function CIS parsing")
Signed-off-by: Matthew Ma <mahongwei@zeku.com>
Reviewed-by: Weizhao Ouyang <ouyangweizhao@zeku.com>
Reviewed-by: John Wang <wangdayu@zeku.com>
---
 drivers/mmc/core/sdio_bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Ulf Hansson Oct. 11, 2022, 2:40 p.m. UTC | #1
On Tue, 27 Sept 2022 at 04:04, Weizhao Ouyang <ouyangweizhao@zeku.com> wrote:
>
> From: Matthew Ma <mahongwei@zeku.com>
>
> SDIO tuple is only allocated for standard SDIO card, especially it
> causes memory corruption issues when the non-standard SDIO card has
> removed since the card device's reference counter does not increase for
> it at sdio_init_func(), but all SDIO card device reference counter has
> decreased at sdio_release_func().
>
> Fixes: 1a632f8cdc33 ("sdio: split up common and function CIS parsing")
> Signed-off-by: Matthew Ma <mahongwei@zeku.com>
> Reviewed-by: Weizhao Ouyang <ouyangweizhao@zeku.com>
> Reviewed-by: John Wang <wangdayu@zeku.com>

Apologize for the delay!

Wow, that's a very old bug you fixed! However, it looks like the fixed
commit should be changed to 6f51be3d37df ("sdio: allow non-standard
SDIO cards").

I tried to apply the patch, but the patch format seems to be corrupt.
Did you use git format-patch and did run ./scripts/checkpatch.pl on
it?

Kind regards
Uffe

> ---
>  drivers/mmc/core/sdio_bus.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
> index c6268c38c69e..babf21a0adeb 100644
> --- a/drivers/mmc/core/sdio_bus.c
> +++ b/drivers/mmc/core/sdio_bus.c
> @@ -291,7 +291,8 @@ static void sdio_release_func(struct device *dev)
>  {
>         struct sdio_func *func = dev_to_sdio_func(dev);
>
> -       sdio_free_func_cis(func);
> +       if (!(func->card->quirks & MMC_QUIRK_NONSTD_SDIO))
> +               sdio_free_func_cis(func);
>
>         kfree(func->info);
>         kfree(func->tmpbuf);
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index c6268c38c69e..babf21a0adeb 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -291,7 +291,8 @@  static void sdio_release_func(struct device *dev)
 {
	struct sdio_func *func = dev_to_sdio_func(dev);
 
-	sdio_free_func_cis(func);
+	if (!(func->card->quirks & MMC_QUIRK_NONSTD_SDIO))
+		sdio_free_func_cis(func);
 
	kfree(func->info);
	kfree(func->tmpbuf);