[RFC v2 02/20] blk: add a helper function, blk_probe_or_unbind()

AKASHI Takahiro takahiro.akashi at linaro.org
Fri Dec 10 07:49:29 CET 2021


This function will be commonly used in block device drivers
in the succeeding patches.

Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
---
 drivers/block/blk-uclass.c | 13 +++++++++++++
 include/blk.h              | 12 ++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 83682dcc181a..f7ad90e8890f 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -670,6 +670,19 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name,
 	return 0;
 }
 
+int blk_probe_or_unbind(struct udevice *dev)
+{
+	int ret;
+
+	ret = device_probe(dev);
+	if (ret) {
+		debug("probing %s failed\n", dev->name);
+		device_unbind(dev);
+	}
+
+	return ret;
+}
+
 int blk_unbind_all(int if_type)
 {
 	struct uclass *uc;
diff --git a/include/blk.h b/include/blk.h
index f0cc7ca1a28c..ef79e7b27b0a 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -369,6 +369,18 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name,
 		       const char *name, int if_type, int devnum, int blksz,
 		       lbaint_t lba, struct udevice **devp);
 
+/**
+ * blk_probe_or_unbind() - Try to probe
+ *
+ * Try to probe the device, primarily for enumelating partitions.
+ * If it fails, the device itself is unbound since it means that it won't
+ * work any more.
+ *
+ * @dev:	The device to probe
+ * @return 0 if OK, -ve on error
+ */
+int blk_probe_or_unbind(struct udevice *dev);
+
 /**
  * blk_unbind_all() - Unbind all device of the given interface type
  *
-- 
2.33.0



More information about the U-Boot mailing list