Rebinding of the mmc driver causes reregistration of block device.
Thus second mmc device appears and the first becomes broken.

Fix an issue by using already registered block device instead of
registering a new one.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevets...@iopsys.eu>
---
 drivers/mmc/mmc-uclass.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index 24170c59ecc..403d20dad53 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -420,11 +420,17 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const 
struct mmc_config *cfg)
        /* Use the fixed index with aliases node's index */
        debug("%s: alias devnum=%d\n", __func__, dev_seq(dev));
 
-       ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
-                                dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
-       if (ret) {
-               debug("Cannot create block device\n");
-               return ret;
+#if CONFIG_IS_ENABLED(MULTI_DTB_FIT_RESCAN)
+       device_find_first_child_by_uclass(dev, UCLASS_BLK, &bdev);
+       if (!bdev)
+#endif
+       {
+               ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
+                                        dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
+               if (ret) {
+                       debug("Cannot create block device\n");
+                       return ret;
+               }
        }
        bdesc = dev_get_uclass_plat(bdev);
        mmc->cfg = cfg;
-- 
2.43.0

Reply via email to