Skip to contentSkip to conversation

mmc: Avoid uniniting twice

PATCH Applied Simon Glass 2 participants 2 messages Feb 16, 2025 – Apr 11, 2025 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: Avoid uniniting twice

Each MMC device has a child which ihs a block device. At present we call mmc_deinit() when the block device is removed.

But the MMC struct (i.e. struct mmc) is attached to the MMC's device, not its child.

So at present, when an MMC device is removed, mmc_deinit() is called twice, once for the MMC device and once for its block device. This results in a double call to cyclic_unregister().

Fix this by adding a 'remove' method to the uclass and calling mmc_deinit() from there.

Also drop the call to device_probe() within the block-device's probe() method. The device is already in the process of being probed, so this call does nothing.

Fixes c822c1a50bd ("mmc: call device_probe() after scanning")

---

 drivers/mmc/mmc-uclass.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
drivers/mmc/mmc-uclass.c +3 -13
index c8db4f811c2..9af84da1599 100644
@@ -498,22 +498,12 @@ static int mmc_blk_probe(struct udevice *dev)
 		return ret;
 	}
 
-	ret = device_probe(dev);
-	if (ret) {
-		debug("Probing %s failed (err=%d)\n", dev->name, ret);
-
-		mmc_deinit(mmc);
-
-		return ret;
-	}
-
 	return 0;
 }
 
-static int mmc_blk_remove(struct udevice *dev)
+static int mmc_remove(struct udevice *dev)
 {
-	struct udevice *mmc_dev = dev_get_parent(dev);
-	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc_dev);
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
 	struct mmc *mmc = upriv->mmc;
 
 	return mmc_deinit(mmc);
@@ -533,7 +523,6 @@ U_BOOT_DRIVER(mmc_blk) = {
 	.id		= UCLASS_BLK,
 	.ops		= &mmc_blk_ops,
 	.probe		= mmc_blk_probe,
-	.remove		= mmc_blk_remove,
 	.flags		= DM_FLAG_OS_PREPARE,
 };
 #endif /* CONFIG_BLK */
@@ -543,4 +532,5 @@ UCLASS_DRIVER(mmc) = {
 	.name		= "mmc",
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
 	.per_device_auto	= sizeof(struct mmc_uclass_priv),
+	.pre_remove	= mmc_remove,
 };
Signature · 1 line
2.43.0
#1 lore raw

From: Peng Fan <[email protected]>

Quoted 11 lines · Simon Glass

Each MMC device has a child which ihs a block device. At present we call mmc_deinit() when the block device is removed.

But the MMC struct (i.e. struct mmc) is attached to the MMC's device, not its child.

So at present, when an MMC device is removed, mmc_deinit() is called twice, once for the MMC device and once for its block device. This results in a double call to cyclic_unregister().

[...]

Applied, thanks!

[1/1] mmc: Avoid uniniting twice

      commit: d99f8d2d749c0e1b352766281f5f5d71fa845f76

Best regards,

Signature · 1 line
Peng Fan <[email protected]>