From d35d93c2902592a84347a15deac4d67a323694c9 Mon Sep 17 00:00:00 2001 From: Ian Ray Date: Wed, 7 Oct 2026 10:03:12 +0300 Subject: [PATCH 01/11] mmc: sdhci-esdhc-imx: map unsupported driver type to Type B Since commit 5a52c5701a67 ("mmc: core: Fix host controller programming for fixed driver type"), the eMMC driver strength is passed directly to mmc_set_driver_type(), which propagates the value through ios.drv_type all the way to sdhci_set_ios(). For value 4, SDHCI correctly warns: mmc2: invalid driver type, default to driver type B The host driver type has no effect on this controller: esdhc_writew_le() never programs the driver-type field of SDHCI_HOST_CONTROL2. Hook set_ios() and force drv_type to the always-valid Type B, so that SDHCI never sees an unsupported value. Tested on i.MX8MP (usdhc3, eMMC in HS400) with `fixed-emmc-driver-type = <4>`: the warning is gone and the HS_TIMING register contains 0x43 as expected. Fixes: 5a52c5701a67 ("mmc: core: Fix host controller programming for fixed driver type") Link: https://lore.kernel.org/all/20260926122908.866-1-ian.ray@gehealthcare.com/ Cc: stable@vger.kernel.org Suggested-by: Adrian Hunter Signed-off-by: Ian Ray Acked-by: Adrian Hunter Reviewed-by: Haibo Chen Signed-off-by: Ulf Hansson --- drivers/mmc/host/sdhci-esdhc-imx.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c index 6ab59d3e346f..931e383748a9 100644 --- a/drivers/mmc/host/sdhci-esdhc-imx.c +++ b/drivers/mmc/host/sdhci-esdhc-imx.c @@ -1142,6 +1142,20 @@ static void esdhc_reset_tuning(struct sdhci_host *host) } } +static void sdhci_esdhc_imx_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) +{ + /* + * This controller has no driver-type control: esdhc_writew_le() + * discards the driver-type field when writing SDHCI_HOST_CONTROL2. + * The programmed value is therefore irrelevant, but SDHCI rejects + * non-SD values such as 4 (eMMC 40 ohm, from fixed-emmc-driver-type). + * Force an always-valid Type B. + */ + ios->drv_type = MMC_SET_DRIVER_TYPE_B; + + sdhci_set_ios(mmc, ios); +} + static void usdhc_init_card(struct mmc_host *mmc, struct mmc_card *card) { struct sdhci_host *host = mmc_priv(mmc); @@ -1952,6 +1966,9 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) host->max_timeout_count = 0xF; } + /* No SDHCI driver type control */ + host->mmc_host_ops.set_ios = sdhci_esdhc_imx_set_ios; + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) sdhci_esdhc_ops.platform_execute_tuning = esdhc_executing_tuning; From c931c51681e33b24bc8d65c6df35b70e1827daa2 Mon Sep 17 00:00:00 2001 From: Runyu Xiao Date: Tue, 29 Sep 2026 20:45:22 +0800 Subject: [PATCH 02/11] mmc: omap: synchronize clock timer before disabling fclk mmc_omap_select_slot() removes clk_timer with timer_delete() before switching slots and changing the functional clock state. timer_delete() only removes a pending timer and does not wait for a callback that is already running. If mmc_omap_clk_timer() is already running, it can therefore call mmc_omap_fclk_enable() while the request or slot-switch path changes the same clock state. During host removal, the same window can overlap the final clock shutdown. Use timer_delete_sync() so the callback has completed before slot switching or changing the functional clock state. Keep the timer restartable for normal request handling. Fixes: 0807a9b5739a ("MMC: OMAP: Lazy clock shutdown") Cc: stable@vger.kernel.org Signed-off-by: Runyu Xiao Signed-off-by: Ulf Hansson --- drivers/mmc/host/omap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c index 527b89a5ed70..02d288e4e9dc 100644 --- a/drivers/mmc/host/omap.c +++ b/drivers/mmc/host/omap.c @@ -214,7 +214,7 @@ static void mmc_omap_select_slot(struct mmc_omap_slot *slot, int claimed) host->mmc = slot->mmc; spin_unlock_irqrestore(&host->slot_lock, flags); no_claim: - timer_delete(&host->clk_timer); + timer_delete_sync(&host->clk_timer); if (host->current_slot != slot || !claimed) mmc_omap_fclk_offdelay(host->current_slot); @@ -273,7 +273,7 @@ static void mmc_omap_release_slot(struct mmc_omap_slot *slot, int clk_enabled) /* Keeps clock running for at least 8 cycles on valid freq */ mod_timer(&host->clk_timer, jiffies + HZ/10); else { - timer_delete(&host->clk_timer); + timer_delete_sync(&host->clk_timer); mmc_omap_fclk_offdelay(slot); mmc_omap_fclk_enable(host, 0); } From 6f2b998a52746892968741cbf8fc226985cbf286 Mon Sep 17 00:00:00 2001 From: Joshua Mulloy Date: Sun, 4 Oct 2026 06:28:48 -0400 Subject: [PATCH 03/11] memstick: core: don't clear dev->driver in memstick_device_remove() memstick_device_remove() sets card->dev.driver to NULL after calling the driver's remove() callback. Since commit a995fe1a3aa7 ("rust: driver: drop device private data post unbind"), device_unbind_cleanup() dereferences dev->driver after the bus remove() callback has returned, so this should result in a NULL pointer dereference whenever a MemoryStick card is removed or its driver is unbound. The driver core clears dev->driver itself in device_unbind_cleanup(), so there is no need for the bus code to do it. Remove the assignment. This was found by code inspection, with the help of an AI coding assistant, after hitting the same bug in the TI FlashMedia bus code (drivers/misc/tifm_core.c), which oopsed on SD card removal. It has only been compile-tested: no MemoryStick hardware was available. Fixes: a995fe1a3aa7 ("rust: driver: drop device private data post unbind") Cc: stable@vger.kernel.org Signed-off-by: Joshua Mulloy Signed-off-by: Ulf Hansson --- drivers/memstick/core/memstick.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c index 0d15f48ef51d..6a80570ee01d 100644 --- a/drivers/memstick/core/memstick.c +++ b/drivers/memstick/core/memstick.c @@ -100,7 +100,6 @@ static void memstick_device_remove(struct device *dev) if (dev->driver && drv->remove) { drv->remove(card); - card->dev.driver = NULL; } put_device(dev); From cf4a8d8b82db7f8e88e6ef4f3020a72860a9c440 Mon Sep 17 00:00:00 2001 From: Karl Mehltretter Date: Fri, 9 Oct 2026 02:32:01 +0200 Subject: [PATCH 04/11] mmc: sdhci-brcmstb: don't log an error for missing BOOT registers The BOOT register range is optional: the probe function ignores a failure to map it and the suspend/resume code checks for NULL. It is mapped with devm_platform_get_and_ioremap_resource(), though, which calls dev_err_probe() when the resource does not exist. Every non-removable host without a third reg entry therefore logs an error at probe time and then works normally. The binding only describes the "host" and "cfg" ranges, so this is the case for the in-tree users. On the Raspberry Pi 5 family (BCM2712), where the SDIO host of the Wi-Fi module is non-removable, each boot prints: sdhci-brcmstb 1001100000.mmc: error -EINVAL: invalid resource (null) Look the resource up with platform_get_resource() first and map it only when it is present. Hosts that do have the range are mapped by the same two calls as before. Fixes: b7e614802e3f ("mmc: sdhci-brcmstb: save and restore registers during PM") Cc: stable@vger.kernel.org Signed-off-by: Karl Mehltretter Reviewed-by: Gregor Herburger Acked-by: Adrian Hunter Reviewed-by: Florian Fainelli Reviewed-by: Kamal Dasu Signed-off-by: Ulf Hansson --- drivers/mmc/host/sdhci-brcmstb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/sdhci-brcmstb.c b/drivers/mmc/host/sdhci-brcmstb.c index 1de2f05fd958..7c17a3cd6a6c 100644 --- a/drivers/mmc/host/sdhci-brcmstb.c +++ b/drivers/mmc/host/sdhci-brcmstb.c @@ -491,6 +491,7 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev) struct sdhci_brcmstb_priv *priv; u32 actual_clock_mhz; struct sdhci_host *host; + struct resource *boot_res; struct clk *clk; struct clk *base_clk = NULL; int res; @@ -534,9 +535,13 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev) /* map non-standard BOOT registers if present */ if (host->mmc->caps & MMC_CAP_NONREMOVABLE) { - priv->boot_regs = devm_platform_get_and_ioremap_resource(pdev, 2, NULL); - if (IS_ERR(priv->boot_regs)) - priv->boot_regs = NULL; + boot_res = platform_get_resource(pdev, IORESOURCE_MEM, 2); + if (boot_res) { + priv->boot_regs = devm_ioremap_resource(&pdev->dev, + boot_res); + if (IS_ERR(priv->boot_regs)) + priv->boot_regs = NULL; + } } /* From e1644210d15f7f8adbe6315199b4b73bead63a2c Mon Sep 17 00:00:00 2001 From: Igor Velkov Date: Fri, 9 Oct 2026 17:02:57 +0000 Subject: [PATCH 05/11] mmc: meson-gx: name the limit of the CMD_CFG timeout field The data timeout is capped at a literal 32768 ms with a comment next to it. Give the limit a name beside the other timeout constants. Fixes: 51c5d8447bd7 ("MMC: meson: initial support for GX platforms") Cc: stable@vger.kernel.org Signed-off-by: Igor Velkov Reviewed-by: Neil Armstrong Signed-off-by: Ulf Hansson --- drivers/mmc/host/meson-gx-mmc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 7ef16d7c03cb..06479ba38525 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -125,6 +125,7 @@ #define SD_EMMC_CFG_RESP_TIMEOUT 256 /* in clock cycles */ #define SD_EMMC_CMD_TIMEOUT 1024 /* in ms */ #define SD_EMMC_CMD_TIMEOUT_DATA 4096 /* in ms */ +#define SD_EMMC_CMD_TIMEOUT_MAX 32768 /* in ms, 2^15: limit of CMD_CFG_TIMEOUT_MASK */ #define SD_EMMC_CFG_CMD_GAP 16 /* in clock cycles */ #define SD_EMMC_DESC_BUF_LEN PAGE_SIZE @@ -212,7 +213,7 @@ static unsigned int meson_mmc_get_timeout_msecs(struct mmc_data *data) timeout = roundup_pow_of_two(timeout); - return min(timeout, 32768U); /* max. 2^15 ms */ + return min_t(unsigned int, timeout, SD_EMMC_CMD_TIMEOUT_MAX); } static struct mmc_command *meson_mmc_get_next_command(struct mmc_command *cmd) From 7e3cc541aa5855bc36e6cbffa82efc2795955a10 Mon Sep 17 00:00:00 2001 From: Igor Velkov Date: Fri, 9 Oct 2026 17:02:58 +0000 Subject: [PATCH 06/11] mmc: meson-gx: honour the busy timeout for R1b commands For a command without data the driver programs a fixed 1024 ms into the CMD_CFG timeout field, and for R1b the controller waits for the card to release busy within that time. The core sends erase and cache flush as R1b with busy timeouts of up to 60 s and 30 s, and the controller gives up after one second: mmc_erase: erase error -110, status 0x0 mmc1: cache flush error -110 Program the timeout from cmd->busy_timeout, kept between 1024 ms, the fixed value until now, and 32768 ms, the most the field holds, and rounded up to a power of two. The clamp comes first: MMC_IOC_CMD passes cmd_timeout_ms from user space straight into busy_timeout, and roundup_pow_of_two() of a value above 2^31 does not fit in unsigned int. sdhci takes its command timeout from cmd->busy_timeout in the same way. Fixes: 51c5d8447bd7 ("MMC: meson: initial support for GX platforms") Cc: stable@vger.kernel.org Signed-off-by: Igor Velkov Reviewed-by: Neil Armstrong Signed-off-by: Ulf Hansson --- drivers/mmc/host/meson-gx-mmc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 06479ba38525..dd246ad63653 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -216,6 +216,20 @@ static unsigned int meson_mmc_get_timeout_msecs(struct mmc_data *data) return min_t(unsigned int, timeout, SD_EMMC_CMD_TIMEOUT_MAX); } +/* For R1b the controller waits for busy to be released within this timeout. */ +static unsigned int meson_mmc_get_cmd_timeout_msecs(struct mmc_command *cmd) +{ + unsigned int timeout = cmd->busy_timeout; + + if (!timeout) + return SD_EMMC_CMD_TIMEOUT; + + timeout = clamp_t(unsigned int, timeout, SD_EMMC_CMD_TIMEOUT, + SD_EMMC_CMD_TIMEOUT_MAX); + + return roundup_pow_of_two(timeout); +} + static struct mmc_command *meson_mmc_get_next_command(struct mmc_command *cmd) { if (cmd->opcode == MMC_SET_BLOCK_COUNT && !cmd->error) @@ -842,7 +856,7 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) cmd_data = host->bounce_dma_addr & CMD_DATA_MASK; } else { cmd_cfg |= FIELD_PREP(CMD_CFG_TIMEOUT_MASK, - ilog2(SD_EMMC_CMD_TIMEOUT)); + ilog2(meson_mmc_get_cmd_timeout_msecs(cmd))); } /* Last descriptor */ From 318fdb75f4dc9d18ae621b9fb25eb11160c95649 Mon Sep 17 00:00:00 2001 From: Igor Velkov Date: Fri, 9 Oct 2026 17:02:59 +0000 Subject: [PATCH 07/11] mmc: meson-gx: report busy from DAT0 alone meson_mmc_card_busy() reports busy only while DAT0..3 are all low. A busy card drives DAT0 low and leaves DAT1..3 to the pull-ups, and the callback is defined as "Check if the card is pulling dat[0] low". So a busy card is reported free, and the core, which prefers card_busy over CMD13 in mmc_busy_cb(), stops polling after CMD6 and erase at once. The controller hides this on R1b commands, where it waits for busy itself. Once max_busy_timeout is reported, the core sends the longer waits, the 120 s BKOPS and 240 s sanitize switches among them, as R1 and has only the polling left. Look at DAT0 only, as sdhci_card_busy() does. The checks around the voltage switch in mmc_set_uhs_voltage() still hold: the card drives DAT0..3 low together after CMD11 and keeps them low together on failure. Fixes: 186cd8b7f586 ("mmc: meson-gx: implement card_busy callback") Cc: stable@vger.kernel.org Signed-off-by: Igor Velkov Reviewed-by: Neil Armstrong Signed-off-by: Ulf Hansson --- drivers/mmc/host/meson-gx-mmc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index dd246ad63653..abdb12e5f997 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -1095,8 +1095,8 @@ static int meson_mmc_card_busy(struct mmc_host *mmc) regval = readl(host->regs + SD_EMMC_STATUS); - /* We are only interrested in lines 0 to 3, so mask the other ones */ - return !(FIELD_GET(STATUS_DATI, regval) & 0xf); + /* The card signals busy on DAT0 alone. */ + return !(FIELD_GET(STATUS_DATI, regval) & BIT(0)); } static int meson_mmc_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios) From 18e9f7fb05ada68d491ff49165b9644f790e0e0c Mon Sep 17 00:00:00 2001 From: Igor Velkov Date: Fri, 9 Oct 2026 17:03:00 +0000 Subject: [PATCH 08/11] mmc: meson-gx: report the longest busy wait the controller can do The driver does not set max_busy_timeout, so the core takes the host for one that can wait for busy indefinitely and sends erase and cache flush as R1b with busy timeouts of up to 60 s and 30 s. The CMD_CFG timeout field holds at most 32768 ms, so the controller times out first. Report 32768 ms as max_busy_timeout. The core then sizes discards to fit and, for a longer wait, sends R1 and polls for busy itself. Fixes: 51c5d8447bd7 ("MMC: meson: initial support for GX platforms") Cc: stable@vger.kernel.org Signed-off-by: Igor Velkov Reviewed-by: Neil Armstrong Signed-off-by: Ulf Hansson --- drivers/mmc/host/meson-gx-mmc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index abdb12e5f997..49df33bbd8e5 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -1183,6 +1183,9 @@ static int meson_mmc_probe(struct platform_device *pdev) mmc->caps |= MMC_CAP_CMD23; + /* The longest busy wait the CMD_CFG timeout field can hold. */ + mmc->max_busy_timeout = SD_EMMC_CMD_TIMEOUT_MAX; + if (mmc->caps & MMC_CAP_SDIO_IRQ) mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD; From 2d8927fadbf95e2d2dfa95bcc73882d6e19c2ce4 Mon Sep 17 00:00:00 2001 From: Anfernee Cao Date: Sat, 17 Oct 2026 00:37:07 +0800 Subject: [PATCH 09/11] mmc: mmci: fix DMA channel leak when mmc_add_host() fails mmci_probe() calls mmci_dma_setup(), which acquires the RX and TX DMA channels via dma_request_chan(). These channels are not managed by devres, and are released only by mmci_dma_release(). If the following mmc_add_host() fails, probe jumps to the clk_disable label, which only disables the clock. As probe then fails, mmci_remove() is never called, so both DMA channels are leaked. Release them by adding a dedicated unwind label, reached only after mmci_dma_setup(). This issue was found by manual code inspection. Fixes: b38a20f29a49 ("mmc: mmci: fix return value check of mmc_add_host()") Cc: stable@vger.kernel.org Signed-off-by: Anfernee Cao Signed-off-by: Ulf Hansson --- drivers/mmc/host/mmci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 416bdb184ed4..4db5c55b2700 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -2477,11 +2477,13 @@ static int mmci_probe(struct amba_device *dev, ret = mmc_add_host(mmc); if (ret) - goto clk_disable; + goto dma_release; pm_runtime_put(&dev->dev); return 0; +dma_release: + mmci_dma_release(host); clk_disable: clk_disable_unprepare(host->clk); return ret; From e35e360bd66898a977c296ab71fe4bae17ddceb7 Mon Sep 17 00:00:00 2001 From: Anfernee Cao Date: Tue, 20 Oct 2026 23:36:47 +0800 Subject: [PATCH 10/11] mmc: sunxi: fix clock and runtime PM leaks on probe failure sunxi_mmc_resource_request() enables the bus, card, output and sample clocks before returning. Several failure paths later in sunxi_mmc_probe() leave them running: - If devm_request_threaded_irq() fails, the clocks enabled by sunxi_mmc_enable() are never disabled. - If dma_alloc_coherent(), mmc_of_parse() or sunxi_mmc_init_host() fails, probe only frees the DMA buffer and the mmc_host. - If mmc_add_host() fails, runtime PM has already been enabled, but pm_runtime_disable() is never called. Besides leaking the clocks, this leaves the clock enable counts unbalanced, so a reprobe (for example after -EPROBE_DEFER) calls clk_prepare_enable() on the same clocks again. Disable the IRQ and the clocks in the probe error path, and disable runtime PM on the mmc_add_host() failure path. Also handle a failure of devm_request_threaded_irq() in sunxi_mmc_resource_request(). Tested with QEMU's orangepi-pc machine: with forced sunxi_mmc_init_host() and mmc_add_host() failures the MMC clocks stay disabled in clk_summary, and a normal probe with an emulated SD card still works. This issue was found by manual code inspection. Fixes: 3cbcb16095f9 ("mmc: sunxi: Add driver for SD/MMC hosts found on Allwinner sunxi SoCs") Fixes: 9a8e1e8cc2c0 ("mmc: sunxi: Add runtime_pm support") Cc: stable@vger.kernel.org # v4.18+ Signed-off-by: Anfernee Cao Signed-off-by: Ulf Hansson --- drivers/mmc/host/sunxi-mmc.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c index fe4c0f6d73f3..437fdadb5950 100644 --- a/drivers/mmc/host/sunxi-mmc.c +++ b/drivers/mmc/host/sunxi-mmc.c @@ -1354,8 +1354,13 @@ static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host, goto error_disable_mmc; } - return devm_request_threaded_irq(&pdev->dev, host->irq, sunxi_mmc_irq, - sunxi_mmc_handle_manual_stop, 0, "sunxi-mmc", host); + ret = devm_request_threaded_irq(&pdev->dev, host->irq, sunxi_mmc_irq, + sunxi_mmc_handle_manual_stop, 0, + "sunxi-mmc", host); + if (ret) + goto error_disable_mmc; + + return 0; error_disable_mmc: sunxi_mmc_disable(host); @@ -1385,9 +1390,11 @@ static int sunxi_mmc_probe(struct platform_device *pdev) host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &host->sg_dma, GFP_KERNEL); - if (!host->sg_cpu) - return dev_err_probe(&pdev->dev, -ENOMEM, - "Failed to allocate DMA descriptor mem\n"); + if (!host->sg_cpu) { + ret = dev_err_probe(&pdev->dev, -ENOMEM, + "Failed to allocate DMA descriptor mem\n"); + goto error_disable_mmc; + } if (host->cfg->ccu_has_timings_switch) { /* @@ -1467,7 +1474,7 @@ static int sunxi_mmc_probe(struct platform_device *pdev) ret = mmc_add_host(mmc); if (ret) - goto error_free_dma; + goto error_disable_rpm; dev_info(&pdev->dev, "initialized, max. request size: %u KB%s\n", mmc->max_req_size >> 10, @@ -1475,8 +1482,13 @@ static int sunxi_mmc_probe(struct platform_device *pdev) return 0; +error_disable_rpm: + pm_runtime_disable(&pdev->dev); error_free_dma: dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma); +error_disable_mmc: + disable_irq(host->irq); + sunxi_mmc_disable(host); return ret; } From 6b8b1e8827837bf4cf1f87219038fddae9e81b0b Mon Sep 17 00:00:00 2001 From: Olivier Louvignes Date: Mon, 26 Oct 2026 09:33:23 +0100 Subject: [PATCH 11/11] mmc: jz4740: Remove the host before resetting the controller jz4740_mmc_remove() masks every interrupt and resets the controller before mmc_remove_host(), which removes the card and lets the card's driver send its last commands. Those commands then run on a controller that was just reset, and can wait out the driver's 5 s request timeout. With an SDIO card that cost 5 s on every unbind: on a HiBy R1 (Ingenic X1600, a BCM43430A1 driven by brcmfmac), the CMD52 that sdio_release_irq() sends from brcmfmac's remove waited 5.1 s. The command had finished (END_CMD_RES set in MSC_STAT), but MSC_IMASK read 0xffffffff although the request had unmasked END_CMD_RES. MSC_STAT can still show IS_RESETTING after jz4740_mmc_reset() returns, so the reset most likely completed after that write and undid it. Remove the host first, then quiesce the controller, as other host drivers do. On the R1, unbinding the Wi-Fi's MSC now takes 0.65 s. Fixes: 61bfbdb85687 ("MMC: Add support for the controller on JZ4740 SoCs.") Cc: stable@vger.kernel.org Signed-off-by: Olivier Louvignes Signed-off-by: Ulf Hansson --- drivers/mmc/host/jz4740_mmc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c index 6a3c26b7c82d..923cf1450de5 100644 --- a/drivers/mmc/host/jz4740_mmc.c +++ b/drivers/mmc/host/jz4740_mmc.c @@ -1151,12 +1151,13 @@ static void jz4740_mmc_remove(struct platform_device *pdev) { struct jz4740_mmc_host *host = platform_get_drvdata(pdev); + /* The card's driver may still send commands as it goes */ + mmc_remove_host(host->mmc); + timer_delete_sync(&host->timeout_timer); jz4740_mmc_set_irq_enabled(host, 0xff, false); jz4740_mmc_reset(host); - mmc_remove_host(host->mmc); - free_irq(host->irq, host); if (host->use_dma)