Re: [PATCH] mmc: cavium: destroy slot platform devices on remove
From: Ulf Hansson
Date: Mon Sep 28 2026 - 12:14:16 EST
On Tue, Sep 15, 2026 at 6:29 PM Guangshuo Li <lgs201920130244@xxxxxxxxx> wrote:
>
> thunder_mmc_probe() creates host->slot_pdev[i] with
> of_platform_device_create(), while thunder_mmc_remove() does not destroy
> the child platform devices.
>
> The probe failure path removes each MMC slot and destroys its associated
> platform device, but the normal remove path only removes the MMC slot.
> As a result, the child platform devices remain registered after the
> ThunderX MMC controller is removed.
>
> Destroy each slot platform device during removal after cleaning up the
> corresponding MMC slot, matching the probe failure cleanup path. Keep an
> extra device reference around of_platform_device_destroy() as done in
> the existing error path.
>
> This issue was found by manual code inspection.
>
> Fixes: 166bac38c3c56 ("mmc: cavium: Add MMC PCI driver for ThunderX SOCs")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
Applied for fixes, though by dropping the redundant calls to
get|put_device(), thanks!
Kind regards
Uffe
> ---
> drivers/mmc/host/cavium-thunderx.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/cavium-thunderx.c b/drivers/mmc/host/cavium-thunderx.c
> index 84ff6d82ae3c..c80907aaf51b 100644
> --- a/drivers/mmc/host/cavium-thunderx.c
> +++ b/drivers/mmc/host/cavium-thunderx.c
> @@ -173,9 +173,15 @@ static void thunder_mmc_remove(struct pci_dev *pdev)
> u64 dma_cfg;
> int i;
>
> - for (i = 0; i < CAVIUM_MAX_MMC; i++)
> + for (i = 0; i < CAVIUM_MAX_MMC; i++) {
> if (host->slot[i])
> cvm_mmc_of_slot_remove(host->slot[i]);
> + if (host->slot_pdev[i]) {
> + get_device(&host->slot_pdev[i]->dev);
> + of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
> + put_device(&host->slot_pdev[i]->dev);
> + }
> + }
>
> dma_cfg = readq(host->dma_base + MIO_EMM_DMA_CFG(host));
> dma_cfg &= ~MIO_EMM_DMA_CFG_EN;
> --
> 2.43.0
>