UPSTREAM: of: Reimplement of_machine_is_compatible() using of_machine_compatible_match()

of_machine_compatible_match() works with a table of strings.
of_machine_is_compatible() is a simplier version with only one string.

Re-implement of_machine_is_compatible() by setting a table of strings
with a single string then using of_machine_compatible_match().

Suggested-by: Rob Herring <robh+dt@kernel.org>
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-3-mpe@ellerman.id.au

Bug: 339841691
(cherry picked from commit 1ac8205f90)
Change-Id: I8cd7ba759bb867780438ed31a06d99ed2b43581a
Signed-off-by: Zhipeng Wang <zhipeng.wang_1@nxp.com>
This commit is contained in:
Christophe Leroy 2023-12-14 21:31:50 +11:00 committed by Carlos Llamas
parent dcc1709075
commit eb1aa949d5
2 changed files with 14 additions and 21 deletions

View File

@ -414,26 +414,7 @@ bool of_machine_compatible_match(const char *const *compats)
return rc != 0;
}
/**
* of_machine_is_compatible - Test root of device tree for a given compatible value
* @compat: compatible string to look for in root node's compatible property.
*
* Return: true if the root node has the given value in its compatible property.
*/
bool of_machine_is_compatible(const char *compat)
{
struct device_node *root;
int rc = 0;
root = of_find_node_by_path("/");
if (root) {
rc = of_device_is_compatible(root, compat);
of_node_put(root);
}
return rc;
}
EXPORT_SYMBOL(of_machine_is_compatible);
EXPORT_SYMBOL(of_machine_compatible_match);
/**
* __of_device_is_available - check if a device is available for use

View File

@ -402,9 +402,21 @@ extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern int of_alias_get_highest_id(const char *stem);
extern bool of_machine_is_compatible(const char *compat);
bool of_machine_compatible_match(const char *const *compats);
/**
* of_machine_is_compatible - Test root of device tree for a given compatible value
* @compat: compatible string to look for in root node's compatible property.
*
* Return: true if the root node has the given value in its compatible property.
*/
static inline bool of_machine_is_compatible(const char *compat)
{
const char *compats[] = { compat, NULL };
return of_machine_compatible_match(compats);
}
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);