1 From bd7a7ed774afd1a4174df34227626c95573be517 Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Tue, 4 Apr 2023 18:21:17 +0100
4 Subject: [PATCH] of: Move of_modalias() to module.c
6 Create a specific .c file for OF related module handling.
7 Move of_modalias() inside as a first step.
9 The helper is exposed through of.h even though it is only used by core
10 files because the users from device.c will soon be split into an OF-only
11 helper in module.c as well as a device-oriented inline helper in
12 of_device.h. Putting this helper in of_private.h would require to
13 include of_private.h from of_device.h, which is not acceptable.
15 Suggested-by: Rob Herring <robh+dt@kernel.org>
16 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
17 Reviewed-by: Rob Herring <robh@kernel.org>
18 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
19 Link: https://lore.kernel.org/r/20230404172148.82422-10-srinivas.kandagatla@linaro.org
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 drivers/of/Makefile | 2 +-
23 drivers/of/device.c | 37 -------------------------------------
24 drivers/of/module.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
25 include/linux/of.h | 9 +++++++++
26 4 files changed, 54 insertions(+), 38 deletions(-)
27 create mode 100644 drivers/of/module.c
29 --- a/drivers/of/Makefile
30 +++ b/drivers/of/Makefile
32 # SPDX-License-Identifier: GPL-2.0
33 -obj-y = base.o device.o platform.o property.o
34 +obj-y = base.o device.o module.o platform.o property.o
35 obj-$(CONFIG_OF_KOBJ) += kobj.o
36 obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
37 obj-$(CONFIG_OF_FLATTREE) += fdt.o
38 --- a/drivers/of/device.c
39 +++ b/drivers/of/device.c
41 // SPDX-License-Identifier: GPL-2.0
42 -#include <linux/string.h>
43 #include <linux/kernel.h>
45 #include <linux/of_device.h>
46 @@ -248,42 +247,6 @@ const void *of_device_get_match_data(con
48 EXPORT_SYMBOL(of_device_get_match_data);
50 -static ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
59 - /* %p eats all alphanum characters, so %c must be used here */
60 - csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
61 - of_node_get_device_type(np));
67 - of_property_for_each_string(np, "compatible", p, compat) {
68 - csize = strlen(compat) + 1;
73 - csize = snprintf(str, len, "C%s", compat);
74 - for (c = str; c; ) {
86 int of_device_request_module(struct device *dev)
90 +++ b/drivers/of/module.c
92 +// SPDX-License-Identifier: GPL-2.0
94 + * Linux kernel module helpers.
97 +#include <linux/of.h>
98 +#include <linux/slab.h>
99 +#include <linux/string.h>
101 +ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
103 + const char *compat;
105 + struct property *p;
110 + /* %p eats all alphanum characters, so %c must be used here */
111 + csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
112 + of_node_get_device_type(np));
118 + of_property_for_each_string(np, "compatible", p, compat) {
119 + csize = strlen(compat) + 1;
124 + csize = snprintf(str, len, "C%s", compat);
125 + for (c = str; c; ) {
126 + c = strchr(c, ' ');
136 --- a/include/linux/of.h
137 +++ b/include/linux/of.h
138 @@ -374,6 +374,9 @@ extern int of_parse_phandle_with_args_ma
139 extern int of_count_phandle_with_args(const struct device_node *np,
140 const char *list_name, const char *cells_name);
142 +/* module functions */
143 +extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len);
145 /* phandle iterator functions */
146 extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
147 const struct device_node *np,
148 @@ -731,6 +734,12 @@ static inline int of_count_phandle_with_
152 +static inline ssize_t of_modalias(const struct device_node *np, char *str,
158 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
159 const struct device_node *np,
160 const char *list_name,