diff options
author | Yong Wu <yong.wu@mediatek.com> | 2022-02-14 09:07:57 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-02-25 14:16:12 +0300 |
commit | 2502960fba7e94e090112069694365295c32ccc5 (patch) | |
tree | a2b68a46e1c3b115f90f1e99ff543333d102eb75 /drivers/base/component.c | |
parent | 36744c117ab4e3d7e114c10d66882c418ba6ea8a (diff) | |
download | linux-2502960fba7e94e090112069694365295c32ccc5.tar.xz |
component: Add common helper for compare/release functions
The component requires the compare/release functions, there are so many
copies in current kernel. Just define four common helpers for them.
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
Link: https://lore.kernel.org/r/20220214060819.7334-2-yong.wu@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/component.c')
-rw-r--r-- | drivers/base/component.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/base/component.c b/drivers/base/component.c index 34f9e0802719..5eadeac6c532 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -6,6 +6,7 @@ #include <linux/device.h> #include <linux/list.h> #include <linux/mutex.h> +#include <linux/of.h> #include <linux/slab.h> #include <linux/debugfs.h> @@ -283,6 +284,63 @@ static void take_down_aggregate_device(struct aggregate_device *adev) } } +/** + * component_compare_of - A common component compare function for of_node + * @dev: component device + * @data: @compare_data from component_match_add_release() + * + * A common compare function when compare_data is device of_node. e.g. + * component_match_add_release(masterdev, &match, component_release_of, + * component_compare_of, component_dev_of_node) + */ +int component_compare_of(struct device *dev, void *data) +{ + return device_match_of_node(dev, data); +} +EXPORT_SYMBOL_GPL(component_compare_of); + +/** + * component_release_of - A common component release function for of_node + * @dev: component device + * @data: @compare_data from component_match_add_release() + * + * About the example, Please see component_compare_of(). + */ +void component_release_of(struct device *dev, void *data) +{ + of_node_put(data); +} +EXPORT_SYMBOL_GPL(component_release_of); + +/** + * component_compare_dev - A common component compare function for dev + * @dev: component device + * @data: @compare_data from component_match_add_release() + * + * A common compare function when compare_data is struce device. e.g. + * component_match_add(masterdev, &match, component_compare_dev, component_dev) + */ +int component_compare_dev(struct device *dev, void *data) +{ + return dev == data; +} +EXPORT_SYMBOL_GPL(component_compare_dev); + +/** + * component_compare_dev_name - A common component compare function for device name + * @dev: component device + * @data: @compare_data from component_match_add_release() + * + * A common compare function when compare_data is device name string. e.g. + * component_match_add(masterdev, &match, component_compare_dev_name, + * "component_dev_name") + */ +int component_compare_dev_name(struct device *dev, void *data) +{ + return device_match_name(dev, data); +} +EXPORT_SYMBOL_GPL(component_compare_dev_name); + static void devm_component_match_release(struct device *parent, void *res) { struct component_match *match = res; |