Skip to content

Commit c029b22

Browse files
committed
of: Add of_machine_compatible_match()
We have of_machine_is_compatible() to check if a machine is compatible with a single compatible string. However some code is able to support multiple compatible boards, and so wants to check for one of many compatible strings. So add of_machine_compatible_match() which takes a NULL terminated array of compatible strings to check against the root node's compatible property. Compared to an open coded match this is slightly more self documenting, and also avoids the caller needing to juggle the root node either directly or via of_find_node_by_path(). Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20231214103152.12269-1-mpe@ellerman.id.au
1 parent af1ebca commit c029b22

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

drivers/of/base.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,27 @@ int of_device_compatible_match(const struct device_node *device,
394394
}
395395
EXPORT_SYMBOL_GPL(of_device_compatible_match);
396396

397+
/**
398+
* of_machine_compatible_match - Test root of device tree against a compatible array
399+
* @compats: NULL terminated array of compatible strings to look for in root node's compatible property.
400+
*
401+
* Returns true if the root node has any of the given compatible values in its
402+
* compatible property.
403+
*/
404+
bool of_machine_compatible_match(const char *const *compats)
405+
{
406+
struct device_node *root;
407+
int rc = 0;
408+
409+
root = of_find_node_by_path("/");
410+
if (root) {
411+
rc = of_device_compatible_match(root, compats);
412+
of_node_put(root);
413+
}
414+
415+
return rc != 0;
416+
}
417+
397418
/**
398419
* of_machine_is_compatible - Test root of device tree for a given compatible value
399420
* @compat: compatible string to look for in root node's compatible property.

include/linux/of.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ extern int of_alias_get_id(struct device_node *np, const char *stem);
403403
extern int of_alias_get_highest_id(const char *stem);
404404

405405
extern int of_machine_is_compatible(const char *compat);
406+
bool of_machine_compatible_match(const char *const *compats);
406407

407408
extern int of_add_property(struct device_node *np, struct property *prop);
408409
extern int of_remove_property(struct device_node *np, struct property *prop);
@@ -808,6 +809,11 @@ static inline int of_remove_property(struct device_node *np, struct property *pr
808809
return 0;
809810
}
810811

812+
static inline bool of_machine_compatible_match(const char *const *compats)
813+
{
814+
return false;
815+
}
816+
811817
static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
812818
{
813819
return false;

0 commit comments

Comments
 (0)