Re: [PATCH 2/2] mmc: via-sdmmc: cancel card-detect work on remove

Ulf Hansson <[email protected]> Mon, 27 Jul 2026 18:25:11 +0200
Newsgroups org.kernel.vger.linux-mmc,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <CAPx+jO_2G8o0QGywZNLNrtBoUroaWYJWk-HW4OAHu+qwJ=VbyQ@mail.gmail.com>
On Thu, Jul 23, 2026 at 1:28=E2=80=AFPM Fan Wu <[email protected]> wrote:
>
> Disabling the device interrupt and freeing the IRQ prevents new card-dete=
ct
> work from being queued, but carddet_work already queued by the handler ca=
n
> still run after via_sd_remove() returns. via_sdc_card_detect() recovers t=
he
> host through container_of() and dereferences its MMIO base; once remove()
> returns the host can be freed, so that work would touch freed memory.
>
> Cancel carddet_work after freeing the IRQ and before cancelling
> finish_bh_work, which the card-detect handler can also queue. carddet_wor=
k
> can re-enable the interrupt through via_reset_pcictrl(); mask it again
> afterwards.
>
> This issue was found by an in-house static analysis tool and confirmed by
> manual code review.
>
> Fixes: f0bf7f61b840 ("mmc: Add new via-sdmmc host controller driver")
> Cc: [email protected]
> Assisted-by: Codex:gpt-5.6
> Signed-off-by: Fan Wu <[email protected]>

Applied for next, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/host/via-sdmmc.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
> index 5228a1fe0495..cf7b74835aa3 100644
> --- a/drivers/mmc/host/via-sdmmc.c
> +++ b/drivers/mmc/host/via-sdmmc.c
> @@ -1206,6 +1206,10 @@ static void via_sd_remove(struct pci_dev *pcidev)
>
>         free_irq(pcidev->irq, sdhost);
>
> +       cancel_work_sync(&sdhost->carddet_work);
> +       /* carddet_work may re-enable the interrupt via via_reset_pcictrl=
(). */
> +       writeb(0x0, sdhost->pcictrl_mmiobase + VIA_CRDR_PCIINTCTRL);
> +
>         timer_delete_sync(&sdhost->timer);
>
>         cancel_work_sync(&sdhost->finish_bh_work);
> --
> 2.34.1