[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220214060819.7334-2-yong.wu@mediatek.com>
Date: Mon, 14 Feb 2022 14:07:57 +0800
From: Yong Wu <yong.wu@...iatek.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
David Airlie <airlied@...ux.ie>,
Daniel Vetter <daniel@...ll.ch>,
<dri-devel@...ts.freedesktop.org>
CC: James Wang <james.qian.wang@....com>,
Liviu Dudau <liviu.dudau@....com>,
<iommu@...ts.linux-foundation.org>,
Matthias Brugger <matthias.bgg@...il.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@...onical.com>,
<linux-kernel@...r.kernel.org>, "Joerg Roedel" <joro@...tes.org>,
Will Deacon <will@...nel.org>, Arnd Bergmann <arnd@...db.de>,
Laurent Pinchart <laurent.pinchart@...asonboard.com>,
<linux-mediatek@...ts.infradead.org>,
Chun-Kuang Hu <chunkuang.hu@...nel.org>,
<linux-arm-kernel@...ts.infradead.org>,
"Stephen Boyd" <sboyd@...nel.org>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>,
Hsin-Yi Wang <hsinyi@...omium.org>,
Robin Murphy <robin.murphy@....com>,
Tomasz Figa <tfiga@...omium.org>,
<srv_heupstream@...iatek.com>, Rob Clark <robdclark@...il.com>,
Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
Sebastian Reichel <sre@...nel.org>,
Yong Wu <yong.wu@...iatek.com>,
"Rafael J. Wysocki" <rafael@...nel.org>
Subject: [PATCH 01/23] 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@...uxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>
Signed-off-by: Yong Wu <yong.wu@...iatek.com>
---
I have run "make htmldocs". Due to my poor english, If the grammer is
wrong or need more comments, please help to correct or supplement.
Thanks.
---
drivers/base/component.c | 58 +++++++++++++++++++++++++++++++++++++++
include/linux/component.h | 6 ++++
2 files changed, 64 insertions(+)
diff --git a/drivers/base/component.c b/drivers/base/component.c
index 2d25a6416587..3d72d2820d7d 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -11,6 +11,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>
@@ -287,6 +288,63 @@ static void take_down_master(struct master *master)
}
}
+/**
+ * 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;
diff --git a/include/linux/component.h b/include/linux/component.h
index 16de18f473d7..6bc1c6e7f76d 100644
--- a/include/linux/component.h
+++ b/include/linux/component.h
@@ -82,6 +82,12 @@ struct component_master_ops {
void (*unbind)(struct device *master);
};
+/* A set helper functions for component compare/release */
+int component_compare_of(struct device *dev, void *data);
+void component_release_of(struct device *dev, void *data);
+int component_compare_dev(struct device *dev, void *data);
+int component_compare_dev_name(struct device *dev, void *data);
+
void component_master_del(struct device *,
const struct component_master_ops *);
--
2.18.0
Powered by blists - more mailing lists