Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Geert Uytterhoeven and committed by
Rob Herring (Arm)
82b6c1b5 c1bf6571

+13 -9
+5 -6
drivers/of/base.c
··· 435 435 EXPORT_SYMBOL(of_machine_compatible_match); 436 436 437 437 /** 438 - * of_machine_device_match - Test root of device tree against a of_device_id array 438 + * of_machine_get_match - Test root of device tree against an of_device_id array 439 439 * @matches: NULL terminated array of of_device_id match structures to search in 440 440 * 441 - * Returns true if the root node has any of the given compatible values in its 442 - * compatible property. 441 + * Returns matched entry or NULL 443 442 */ 444 - bool of_machine_device_match(const struct of_device_id *matches) 443 + const struct of_device_id *of_machine_get_match(const struct of_device_id *matches) 445 444 { 446 445 struct device_node *root; 447 446 const struct of_device_id *match = NULL; ··· 451 452 of_node_put(root); 452 453 } 453 454 454 - return match != NULL; 455 + return match; 455 456 } 456 - EXPORT_SYMBOL(of_machine_device_match); 457 + EXPORT_SYMBOL(of_machine_get_match); 457 458 458 459 /** 459 460 * of_machine_get_match_data - Tell if root of device tree has a matching of_match structure
+8 -3
include/linux/of.h
··· 410 410 extern int of_alias_get_highest_id(const char *stem); 411 411 412 412 bool of_machine_compatible_match(const char *const *compats); 413 - bool of_machine_device_match(const struct of_device_id *matches); 413 + const struct of_device_id *of_machine_get_match(const struct of_device_id *matches); 414 414 const void *of_machine_get_match_data(const struct of_device_id *matches); 415 415 416 416 /** ··· 866 866 return false; 867 867 } 868 868 869 - static inline bool of_machine_device_match(const struct of_device_id *matches) 869 + static inline const struct of_device_id *of_machine_get_match(const struct of_device_id *matches) 870 870 { 871 - return false; 871 + return NULL; 872 872 } 873 873 874 874 static inline const void * ··· 975 975 return -ENOSYS; 976 976 } 977 977 #endif 978 + 979 + static inline bool of_machine_device_match(const struct of_device_id *matches) 980 + { 981 + return of_machine_get_match(matches) != NULL; 982 + } 978 983 979 984 static inline struct device_node *of_find_matching_node( 980 985 struct device_node *from,