Skip to content

Commit 1ac8205

Browse files
chleroympe
authored andcommitted
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
1 parent cefdb36 commit 1ac8205

2 files changed

Lines changed: 14 additions & 21 deletions

File tree

drivers/of/base.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -414,26 +414,7 @@ bool of_machine_compatible_match(const char *const *compats)
414414

415415
return rc != 0;
416416
}
417-
418-
/**
419-
* of_machine_is_compatible - Test root of device tree for a given compatible value
420-
* @compat: compatible string to look for in root node's compatible property.
421-
*
422-
* Return: true if the root node has the given value in its compatible property.
423-
*/
424-
bool of_machine_is_compatible(const char *compat)
425-
{
426-
struct device_node *root;
427-
int rc = 0;
428-
429-
root = of_find_node_by_path("/");
430-
if (root) {
431-
rc = of_device_is_compatible(root, compat);
432-
of_node_put(root);
433-
}
434-
return rc;
435-
}
436-
EXPORT_SYMBOL(of_machine_is_compatible);
417+
EXPORT_SYMBOL(of_machine_compatible_match);
437418

438419
/**
439420
* __of_device_is_available - check if a device is available for use

include/linux/of.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,21 @@ extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
402402
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

405-
extern bool of_machine_is_compatible(const char *compat);
406405
bool of_machine_compatible_match(const char *const *compats);
407406

407+
/**
408+
* of_machine_is_compatible - Test root of device tree for a given compatible value
409+
* @compat: compatible string to look for in root node's compatible property.
410+
*
411+
* Return: true if the root node has the given value in its compatible property.
412+
*/
413+
static inline bool of_machine_is_compatible(const char *compat)
414+
{
415+
const char *compats[] = { compat, NULL };
416+
417+
return of_machine_compatible_match(compats);
418+
}
419+
408420
extern int of_add_property(struct device_node *np, struct property *prop);
409421
extern int of_remove_property(struct device_node *np, struct property *prop);
410422
extern int of_update_property(struct device_node *np, struct property *newprop);

0 commit comments

Comments
 (0)