[PATCH v4 2/7] sysinfo: add sysinfo_get_and_detect() helper

Alexander Feilke Alexander.Feilke at ew.tq-group.com
Tue Jun 2 13:57:50 CEST 2026


From: Nora Schiffer <nora.schiffer at ew.tq-group.com>

sysinfo_detect() is commonly called after sysinfo_get(). Make the API a
bit more convenient to use by introducing a helper.

Signed-off-by: Nora Schiffer <nora.schiffer at ew.tq-group.com>
Signed-off-by: Alexander Feilke <alexander.feilke at ew.tq-group.com>
---
 drivers/sysinfo/sysinfo-uclass.c | 10 ++++++++++
 include/sysinfo.h                | 17 +++++++++++++++++
 test/dm/sysinfo.c                | 16 ++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/drivers/sysinfo/sysinfo-uclass.c b/drivers/sysinfo/sysinfo-uclass.c
index bf0f664e8dc..d18a168614e 100644
--- a/drivers/sysinfo/sysinfo-uclass.c
+++ b/drivers/sysinfo/sysinfo-uclass.c
@@ -42,6 +42,16 @@ int sysinfo_detect(struct udevice *dev)
 	return ret;
 }
 
+int sysinfo_get_and_detect(struct udevice **devp)
+{
+	int ret = sysinfo_get(devp);
+
+	if (!ret)
+		ret = sysinfo_detect(*devp);
+
+	return ret;
+}
+
 int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
 			     const char **strp)
 {
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 54eb64a204a..7ca396b2ee4 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -373,6 +373,18 @@ int sysinfo_get_data_by_index(struct udevice *dev, int id, int index,
  */
 int sysinfo_get(struct udevice **devp);
 
+/**
+ * sysinfo_get_and_detect() - Get the sysinfo device and detect it.
+ *
+ * @devp:	Pointer to structure to receive the sysinfo device.
+ *
+ * This is a convenience wrapper around sysinfo_get() followed by
+ * sysinfo_detect()
+ *
+ * Return: 0 if OK, -ve on error.
+ */
+int sysinfo_get_and_detect(struct udevice **devp);
+
 /**
  * sysinfo_get_fit_loadable - Get the name of an image to load from FIT
  * This function can be used to provide the image names based on runtime
@@ -438,6 +450,11 @@ static inline int sysinfo_get(struct udevice **devp)
 	return -ENOSYS;
 }
 
+static inline int sysinfo_get_and_detect(struct udevice **devp)
+{
+	return -ENOSYS;
+}
+
 static inline int sysinfo_get_fit_loadable(struct udevice *dev, int index,
 					   const char *type, const char **strp)
 {
diff --git a/test/dm/sysinfo.c b/test/dm/sysinfo.c
index 14ebe6b42e7..611f2e98d14 100644
--- a/test/dm/sysinfo.c
+++ b/test/dm/sysinfo.c
@@ -66,3 +66,19 @@ static int dm_test_sysinfo(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_sysinfo, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+static int dm_test_sysinfo_get_and_detect(struct unit_test_state *uts)
+{
+	struct udevice *sysinfo;
+	bool called_detect = false;
+
+	ut_assertok(sysinfo_get_and_detect(&sysinfo));
+	ut_assert(sysinfo);
+
+	ut_assertok(sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT,
+				     &called_detect));
+	ut_assert(called_detect);
+
+	return 0;
+}
+DM_TEST(dm_test_sysinfo_get_and_detect, UTF_SCAN_PDATA | UTF_SCAN_FDT);
-- 
2.34.1



More information about the U-Boot mailing list