summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2026-03-02 19:29:05 +0300
committerRob Herring (Arm) <robh@kernel.org>2026-03-14 01:00:04 +0300
commit82b6c1b542ea0530318c6f2a880d884eb4dce49f (patch)
tree0b4ef9d8e5fd7068351d00bd5612692aca04d0ea
parentc1bf657164413426cb4d7d1231f8a6b949f08188 (diff)
downloadlinux-82b6c1b542ea0530318c6f2a880d884eb4dce49f.tar.xz
of: Add of_machine_get_match() helper
Currently, there are two helpers to match the root compatible value against an of_device_id array: - of_machine_device_match() returns true if a match is found, - of_machine_get_match_data() returns the match data if a match is found. However, there is no helper that returns the actual of_device_id structure corresponding to the match, leading to code duplication in various drivers. Fix this by reworking of_machine_device_match() to return the actual match structure, and renaming it to of_machine_get_match(). Retain the old of_machine_device_match() functionality using a cheap static inline wrapper around the new of_machine_get_match() helper. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Link: https://patch.msgid.link/14e1c03d443b1a5f210609ec3a1ebbaeab8fb3d9.1772468323.git.geert+renesas@glider.be Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
-rw-r--r--drivers/of/base.c11
-rw-r--r--include/linux/of.h11
2 files changed, 13 insertions, 9 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 57420806c1a2..2a01d2a66eed 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -435,13 +435,12 @@ bool of_machine_compatible_match(const char *const *compats)
EXPORT_SYMBOL(of_machine_compatible_match);
/**
- * of_machine_device_match - Test root of device tree against a of_device_id array
+ * of_machine_get_match - Test root of device tree against an of_device_id array
* @matches: NULL terminated array of of_device_id match structures to search in
*
- * Returns true if the root node has any of the given compatible values in its
- * compatible property.
+ * Returns matched entry or NULL
*/
-bool of_machine_device_match(const struct of_device_id *matches)
+const struct of_device_id *of_machine_get_match(const struct of_device_id *matches)
{
struct device_node *root;
const struct of_device_id *match = NULL;
@@ -452,9 +451,9 @@ bool of_machine_device_match(const struct of_device_id *matches)
of_node_put(root);
}
- return match != NULL;
+ return match;
}
-EXPORT_SYMBOL(of_machine_device_match);
+EXPORT_SYMBOL(of_machine_get_match);
/**
* of_machine_get_match_data - Tell if root of device tree has a matching of_match structure
diff --git a/include/linux/of.h b/include/linux/of.h
index be6ec4916adf..b4d7d33b0ceb 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -410,7 +410,7 @@ extern int of_alias_get_id(const struct device_node *np, const char *stem);
extern int of_alias_get_highest_id(const char *stem);
bool of_machine_compatible_match(const char *const *compats);
-bool of_machine_device_match(const struct of_device_id *matches);
+const struct of_device_id *of_machine_get_match(const struct of_device_id *matches);
const void *of_machine_get_match_data(const struct of_device_id *matches);
/**
@@ -866,9 +866,9 @@ static inline bool of_machine_compatible_match(const char *const *compats)
return false;
}
-static inline bool of_machine_device_match(const struct of_device_id *matches)
+static inline const struct of_device_id *of_machine_get_match(const struct of_device_id *matches)
{
- return false;
+ return NULL;
}
static inline const void *
@@ -976,6 +976,11 @@ static inline int of_numa_init(void)
}
#endif
+static inline bool of_machine_device_match(const struct of_device_id *matches)
+{
+ return of_machine_get_match(matches) != NULL;
+}
+
static inline struct device_node *of_find_matching_node(
struct device_node *from,
const struct of_device_id *matches)