diff mbox

[U-Boot,7/8] dm: mmc: Rewrite mmc_blk_probe()

Message ID 20170424020211.20690-8-sjg@chromium.org
State Accepted
Commit 854f9a71f594555858cdffce18f6183a75d1d730
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass April 24, 2017, 2:02 a.m. UTC
This function is called when the MMC block device is being probed. There
is a recursive call in this function since find_mmc_device() itself can
cause the MMC device to be probed.

Admittedly the MMC device should already be probed, since we would not be
probing its child otherwise, but the current code is unnecessarily
convoluted.

Rewrite this to access the MMC structure directly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/mmc/mmc-uclass.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Simon Glass May 18, 2017, 4:01 p.m. UTC | #1
This function is called when the MMC block device is being probed. There
is a recursive call in this function since find_mmc_device() itself can
cause the MMC device to be probed.

Admittedly the MMC device should already be probed, since we would not be
probing its child otherwise, but the current code is unnecessarily
convoluted.

Rewrite this to access the MMC structure directly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/mmc/mmc-uclass.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Applied to u-boot-dm
diff mbox

Patch

diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index ae0e22dfeb..63248c3480 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -262,13 +262,18 @@  static int mmc_select_hwpart(struct udevice *bdev, int hwpart)
 
 static int mmc_blk_probe(struct udevice *dev)
 {
-	struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
-	int dev_num = block_dev->devnum;
-	struct mmc *mmc = find_mmc_device(dev_num);
+	struct udevice *mmc_dev = dev_get_parent(dev);
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(mmc_dev);
+	struct mmc *mmc = upriv->mmc;
+	int ret;
+
+	ret = mmc_init(mmc);
+	if (ret) {
+		debug("%s: mmc_init() failed (err=%d)\n", __func__, ret);
+		return ret;
+	}
 
-	if (!mmc)
-		return -ENODEV;
-	return mmc_init(mmc);
+	return 0;
 }
 
 static const struct blk_ops mmc_blk_ops = {