Skip to contentSkip to conversation

mmc: dw_mmc: Remove struct dw_mci_slot

bug report Dan Carpenter 2 participants 2 messages Dec 19, 2025 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

Hello Shawn Lin,

Commit 926311cf3361 ("mmc: dw_mmc: Remove struct dw_mci_slot") from Dec 16, 2025 (linux-next), leads to the following Smatch static checker warning:

	drivers/mmc/host/dw_mmc.c:3467 dw_mci_remove()
	error: we previously assumed 'host' could be null (see line 3464)

drivers/mmc/host/dw_mmc.c

    3457         return ret;
    3458 }
    3459 EXPORT_SYMBOL(dw_mci_probe);
    3460 
    3461 void dw_mci_remove(struct dw_mci *host)
    3462 {
    3463         dev_dbg(host->dev, "remove host\n");
                         ^^^^^^^^^

Host is dereferenced

    3464         if (host)

Then checked for NULL.

    3465                 dw_mci_cleanup_host(host);

The dw_mci_cleanup_host() function gives up our claim to host which allows it to be re-used.

    3466 

--> 3467 mci_writel(host, RINTSTS, 0xFFFFFFFF);

So it's surprising to me that we keep on using it throughout the rest of the function.

    3468         mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
    3469 
    3470         /* disable clock to CIU */
    3471         mci_writel(host, CLKENA, 0);
    3472         mci_writel(host, CLKSRC, 0);
    3473 
    3474         if (host->use_dma && host->dma_ops->exit)
    3475                 host->dma_ops->exit(host);
    3476 
    3477         reset_control_assert(host->pdata->rstc);
    3478 
    3479         clk_disable_unprepare(host->ciu_clk);
    3480         clk_disable_unprepare(host->biu_clk);
    3481 }

regards,
dan carpenter

#1 lore raw
Quoted 26 lines · Dan Carpenter

Hello Shawn Lin,

Commit 926311cf3361 ("mmc: dw_mmc: Remove struct dw_mci_slot") from Dec 16, 2025 (linux-next), leads to the following Smatch static checker warning:

	drivers/mmc/host/dw_mmc.c:3467 dw_mci_remove()
	error: we previously assumed 'host' could be null (see line 3464)

drivers/mmc/host/dw_mmc.c

     3457         return ret;
     3458 }
     3459 EXPORT_SYMBOL(dw_mci_probe);
     3460
     3461 void dw_mci_remove(struct dw_mci *host)
     3462 {
     3463         dev_dbg(host->dev, "remove host\n");
                          ^^^^^^^^^

Host is dereferenced

     3464         if (host)

Then checked for NULL.

     3465                 dw_mci_cleanup_host(host);
Quoted 9 lines

The dw_mci_cleanup_host() function gives up our claim to host which allows it to be re-used.

     3466

--> 3467 mci_writel(host, RINTSTS, 0xFFFFFFFF);

So it's surprising to me that we keep on using it throughout the rest of the function.

Thanks Dan. Smatch is so smart! Yes, this check is redundant, could be removed. Will fix it later.

Quoted 18 lines
     3468         mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
     3469
     3470         /* disable clock to CIU */
     3471         mci_writel(host, CLKENA, 0);
     3472         mci_writel(host, CLKSRC, 0);
     3473
     3474         if (host->use_dma && host->dma_ops->exit)
     3475                 host->dma_ops->exit(host);
     3476
     3477         reset_control_assert(host->pdata->rstc);
     3478
     3479         clk_disable_unprepare(host->ciu_clk);
     3480         clk_disable_unprepare(host->biu_clk);
     3481 }

regards,
dan carpenter