Thread (27 messages) 27 messages, 9 authors, 2026-02-23

Re: [PATCH 1/8] of: provide of_machine_get_compatible()

From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Date: 2026-01-19 11:06:59
Also in: imx, linux-arm-kernel, linux-devicetree, linux-renesas-soc, linux-sunxi, lkml


Le 19/01/2026 à 11:40, Bartosz Golaszewski a écrit :
Provide a helper function allowing users to read the compatible string
of the machine, hiding the access to the root node.

Signed-off-by: Bartosz Golaszewski <redacted>
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
quoted hunk ↗ jump to hunk
---
  drivers/of/base.c  | 13 +++++++++++++
  include/linux/of.h |  2 ++
  2 files changed, 15 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 0b65039ece53aa90f30da2420a893a02ab4c6dd8..a7e27d5355929abd6d156b80c52f8f8b08fe6da1 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -434,6 +434,19 @@ bool of_machine_compatible_match(const char *const *compats)
  }
  EXPORT_SYMBOL(of_machine_compatible_match);
  
+/**
+ * of_machine_get_compatible - Get the compatible string of this machine
+ * @compatible: address at which the compatible string will be stored
+ *
+ * Returns:
+ * 0 on success, negative error number on failure.
+ */
+int of_machine_get_compatible(const char **compatible)
+{
+	return of_property_read_string(of_root, "compatible", compatible);
+}
+EXPORT_SYMBOL_GPL(of_machine_get_compatible);
+
  /**
   * of_machine_device_match - Test root of device tree against a of_device_id array
   * @matches:	NULL terminated array of of_device_id match structures to search in
diff --git a/include/linux/of.h b/include/linux/of.h
index 9bbdcf25a2b448ba4ec5ddee8b35a105ca4aab8b..75423fb556ee4c108ce25144a0bdc252a89f7d1d 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -426,6 +426,8 @@ static inline bool of_machine_is_compatible(const char *compat)
  	return of_machine_compatible_match(compats);
  }
  
+int of_machine_get_compatible(const char **compatible);
+
  extern int of_add_property(struct device_node *np, struct property *prop);
  extern int of_remove_property(struct device_node *np, struct property *prop);
  extern int of_update_property(struct device_node *np, struct property *newprop);
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help