mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shawn Lin <shawn.lin@rock-chips.com>
To: Tuo Li <islituo@gmail.com>
Cc: shawn.lin@rock-chips.com, linux-mmc@vger.kernel.org,
	linux-kernel@vger.kernel.org, jh80.chung@samsung.com,
	ulf.hansson@linaro.org
Subject: Re: [PATCH] mmc: dw_mmc: Add a defensive check to prevent potential null-pointer dereferences in dw_mci_runtime_resume()
Date: Fri, 12 Dec 2025 08:28:41 +0800	[thread overview]
Message-ID: <7a24821b-d54e-4463-9274-215c027c9be2@rock-chips.com> (raw)
In-Reply-To: <20251211161313.3994317-1-islituo@gmail.com>

Hi Tuo,

在 2025/12/12 星期五 0:13, Tuo Li 写道:
> In this function, the variable host->slot is checked and then dereferenced
> in several places which indicates it can be NULL, for example:
> 
>    if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
> 		dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);
> 
> However, in the following cases, host->slot is dereferenced without a
> preceding NULL check, which introduces a risk of null-pointer dereference:
> 
>    dw_mci_setup_bus(host->slot, true);
> 
>    if (sdio_irq_claimed(host->slot->mmc))
>      __dw_mci_enable_sdio_irq(host->slot, 1);
> 
>    dw_mci_enable_cd(host);
> 
> To prevent such issues, add a defensive check to ensure host->slot is not
> NULL before dereferencing it.
> 

Thanks for your patch. we plan to remove the slot design
entirely soon, probably this cycle.

> Signed-off-by: Tuo Li <islituo@gmail.com>
> ---
>   drivers/mmc/host/dw_mmc.c | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
> index 9e74b675e92d..e74dea0a32d4 100644
> --- a/drivers/mmc/host/dw_mmc.c
> +++ b/drivers/mmc/host/dw_mmc.c
> @@ -3670,15 +3670,18 @@ int dw_mci_runtime_resume(struct device *dev)
>   	if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)
>   		dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios);
>   
> -	/* Force setup bus to guarantee available clock output */
> -	dw_mci_setup_bus(host->slot, true);
>   
> -	/* Re-enable SDIO interrupts. */
> -	if (sdio_irq_claimed(host->slot->mmc))
> -		__dw_mci_enable_sdio_irq(host->slot, 1);
> +	if (host->slot) {
> +		/* Force setup bus to guarantee available clock output */
> +		dw_mci_setup_bus(host->slot, true);
>   
> -	/* Now that slots are all setup, we can enable card detect */
> -	dw_mci_enable_cd(host);
> +		/* Re-enable SDIO interrupts. */
> +		if (sdio_irq_claimed(host->slot->mmc))
> +			__dw_mci_enable_sdio_irq(host->slot, 1);
> +
> +		/* Now that slots are all setup, we can enable card detect */
> +		dw_mci_enable_cd(host);
> +	}
>   
>   	return 0;
>   


  reply	other threads:[~2025-12-12  0:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 16:13 Tuo Li
2025-12-12  0:28 ` Shawn Lin [this message]
2025-12-12  5:13   ` Tuo Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a24821b-d54e-4463-9274-215c027c9be2@rock-chips.com \
    --to=shawn.lin@rock-chips.com \
    --cc=islituo@gmail.com \
    --cc=jh80.chung@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®