b00cf5741991d01425b3c237a254a09fe8840fa4
[openwrt/staging/svanheule.git] /
1 From 66a8f7f04979f4ad739085f01d99c8caf620b4f5 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Tue, 18 Jan 2022 18:35:02 +0100
4 Subject: [PATCH] of: base: make small of_parse_phandle() variants static
5 inline
6
7 Make all the smaller variants of the of_parse_phandle() static inline.
8 This also let us remove the empty function stubs if CONFIG_OF is not
9 defined.
10
11 Suggested-by: Rob Herring <robh@kernel.org>
12 Signed-off-by: Michael Walle <michael@walle.cc>
13 [robh: move index < 0 check into __of_parse_phandle_with_args]
14 Signed-off-by: Rob Herring <robh@kernel.org>
15 Link: https://lore.kernel.org/r/20220118173504.2867523-2-michael@walle.cc
16 ---
17 drivers/of/base.c | 131 +++------------------------------------
18 include/linux/of.h | 148 ++++++++++++++++++++++++++++++++++++---------
19 2 files changed, 129 insertions(+), 150 deletions(-)
20
21 --- a/drivers/of/base.c
22 +++ b/drivers/of/base.c
23 @@ -1371,15 +1371,18 @@ int of_phandle_iterator_args(struct of_p
24 return count;
25 }
26
27 -static int __of_parse_phandle_with_args(const struct device_node *np,
28 - const char *list_name,
29 - const char *cells_name,
30 - int cell_count, int index,
31 - struct of_phandle_args *out_args)
32 +int __of_parse_phandle_with_args(const struct device_node *np,
33 + const char *list_name,
34 + const char *cells_name,
35 + int cell_count, int index,
36 + struct of_phandle_args *out_args)
37 {
38 struct of_phandle_iterator it;
39 int rc, cur_index = 0;
40
41 + if (index < 0)
42 + return -EINVAL;
43 +
44 /* Loop over the phandles until all the requested entry is found */
45 of_for_each_phandle(&it, rc, np, list_name, cells_name, cell_count) {
46 /*
47 @@ -1422,82 +1425,7 @@ static int __of_parse_phandle_with_args(
48 of_node_put(it.node);
49 return rc;
50 }
51 -
52 -/**
53 - * of_parse_phandle - Resolve a phandle property to a device_node pointer
54 - * @np: Pointer to device node holding phandle property
55 - * @phandle_name: Name of property holding a phandle value
56 - * @index: For properties holding a table of phandles, this is the index into
57 - * the table
58 - *
59 - * Return: The device_node pointer with refcount incremented. Use
60 - * of_node_put() on it when done.
61 - */
62 -struct device_node *of_parse_phandle(const struct device_node *np,
63 - const char *phandle_name, int index)
64 -{
65 - struct of_phandle_args args;
66 -
67 - if (index < 0)
68 - return NULL;
69 -
70 - if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
71 - index, &args))
72 - return NULL;
73 -
74 - return args.np;
75 -}
76 -EXPORT_SYMBOL(of_parse_phandle);
77 -
78 -/**
79 - * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
80 - * @np: pointer to a device tree node containing a list
81 - * @list_name: property name that contains a list
82 - * @cells_name: property name that specifies phandles' arguments count
83 - * @index: index of a phandle to parse out
84 - * @out_args: optional pointer to output arguments structure (will be filled)
85 - *
86 - * This function is useful to parse lists of phandles and their arguments.
87 - * Returns 0 on success and fills out_args, on error returns appropriate
88 - * errno value.
89 - *
90 - * Caller is responsible to call of_node_put() on the returned out_args->np
91 - * pointer.
92 - *
93 - * Example::
94 - *
95 - * phandle1: node1 {
96 - * #list-cells = <2>;
97 - * };
98 - *
99 - * phandle2: node2 {
100 - * #list-cells = <1>;
101 - * };
102 - *
103 - * node3 {
104 - * list = <&phandle1 1 2 &phandle2 3>;
105 - * };
106 - *
107 - * To get a device_node of the ``node2`` node you may call this:
108 - * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
109 - */
110 -int of_parse_phandle_with_args(const struct device_node *np, const char *list_name,
111 - const char *cells_name, int index,
112 - struct of_phandle_args *out_args)
113 -{
114 - int cell_count = -1;
115 -
116 - if (index < 0)
117 - return -EINVAL;
118 -
119 - /* If cells_name is NULL we assume a cell count of 0 */
120 - if (!cells_name)
121 - cell_count = 0;
122 -
123 - return __of_parse_phandle_with_args(np, list_name, cells_name,
124 - cell_count, index, out_args);
125 -}
126 -EXPORT_SYMBOL(of_parse_phandle_with_args);
127 +EXPORT_SYMBOL(__of_parse_phandle_with_args);
128
129 /**
130 * of_parse_phandle_with_args_map() - Find a node pointed by phandle in a list and remap it
131 @@ -1684,47 +1612,6 @@ free:
132 EXPORT_SYMBOL(of_parse_phandle_with_args_map);
133
134 /**
135 - * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
136 - * @np: pointer to a device tree node containing a list
137 - * @list_name: property name that contains a list
138 - * @cell_count: number of argument cells following the phandle
139 - * @index: index of a phandle to parse out
140 - * @out_args: optional pointer to output arguments structure (will be filled)
141 - *
142 - * This function is useful to parse lists of phandles and their arguments.
143 - * Returns 0 on success and fills out_args, on error returns appropriate
144 - * errno value.
145 - *
146 - * Caller is responsible to call of_node_put() on the returned out_args->np
147 - * pointer.
148 - *
149 - * Example::
150 - *
151 - * phandle1: node1 {
152 - * };
153 - *
154 - * phandle2: node2 {
155 - * };
156 - *
157 - * node3 {
158 - * list = <&phandle1 0 2 &phandle2 2 3>;
159 - * };
160 - *
161 - * To get a device_node of the ``node2`` node you may call this:
162 - * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
163 - */
164 -int of_parse_phandle_with_fixed_args(const struct device_node *np,
165 - const char *list_name, int cell_count,
166 - int index, struct of_phandle_args *out_args)
167 -{
168 - if (index < 0)
169 - return -EINVAL;
170 - return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
171 - index, out_args);
172 -}
173 -EXPORT_SYMBOL(of_parse_phandle_with_fixed_args);
174 -
175 -/**
176 * of_count_phandle_with_args() - Find the number of phandles references in a property
177 * @np: pointer to a device tree node containing a list
178 * @list_name: property name that contains a list
179 --- a/include/linux/of.h
180 +++ b/include/linux/of.h
181 @@ -363,18 +363,12 @@ extern const struct of_device_id *of_mat
182 const struct of_device_id *matches, const struct device_node *node);
183 extern int of_modalias_node(struct device_node *node, char *modalias, int len);
184 extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
185 -extern struct device_node *of_parse_phandle(const struct device_node *np,
186 - const char *phandle_name,
187 - int index);
188 -extern int of_parse_phandle_with_args(const struct device_node *np,
189 - const char *list_name, const char *cells_name, int index,
190 - struct of_phandle_args *out_args);
191 +extern int __of_parse_phandle_with_args(const struct device_node *np,
192 + const char *list_name, const char *cells_name, int cell_count,
193 + int index, struct of_phandle_args *out_args);
194 extern int of_parse_phandle_with_args_map(const struct device_node *np,
195 const char *list_name, const char *stem_name, int index,
196 struct of_phandle_args *out_args);
197 -extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
198 - const char *list_name, int cells_count, int index,
199 - struct of_phandle_args *out_args);
200 extern int of_count_phandle_with_args(const struct device_node *np,
201 const char *list_name, const char *cells_name);
202
203 @@ -864,18 +858,12 @@ static inline int of_property_read_strin
204 return -ENOSYS;
205 }
206
207 -static inline struct device_node *of_parse_phandle(const struct device_node *np,
208 - const char *phandle_name,
209 - int index)
210 -{
211 - return NULL;
212 -}
213 -
214 -static inline int of_parse_phandle_with_args(const struct device_node *np,
215 - const char *list_name,
216 - const char *cells_name,
217 - int index,
218 - struct of_phandle_args *out_args)
219 +static inline int __of_parse_phandle_with_args(const struct device_node *np,
220 + const char *list_name,
221 + const char *cells_name,
222 + int cell_count,
223 + int index,
224 + struct of_phandle_args *out_args)
225 {
226 return -ENOSYS;
227 }
228 @@ -889,13 +877,6 @@ static inline int of_parse_phandle_with_
229 return -ENOSYS;
230 }
231
232 -static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
233 - const char *list_name, int cells_count, int index,
234 - struct of_phandle_args *out_args)
235 -{
236 - return -ENOSYS;
237 -}
238 -
239 static inline int of_count_phandle_with_args(const struct device_node *np,
240 const char *list_name,
241 const char *cells_name)
242 @@ -1077,6 +1058,117 @@ static inline bool of_node_is_type(const
243 }
244
245 /**
246 + * of_parse_phandle - Resolve a phandle property to a device_node pointer
247 + * @np: Pointer to device node holding phandle property
248 + * @phandle_name: Name of property holding a phandle value
249 + * @index: For properties holding a table of phandles, this is the index into
250 + * the table
251 + *
252 + * Return: The device_node pointer with refcount incremented. Use
253 + * of_node_put() on it when done.
254 + */
255 +static inline struct device_node *of_parse_phandle(const struct device_node *np,
256 + const char *phandle_name,
257 + int index)
258 +{
259 + struct of_phandle_args args;
260 +
261 + if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
262 + index, &args))
263 + return NULL;
264 +
265 + return args.np;
266 +}
267 +
268 +/**
269 + * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
270 + * @np: pointer to a device tree node containing a list
271 + * @list_name: property name that contains a list
272 + * @cells_name: property name that specifies phandles' arguments count
273 + * @index: index of a phandle to parse out
274 + * @out_args: optional pointer to output arguments structure (will be filled)
275 + *
276 + * This function is useful to parse lists of phandles and their arguments.
277 + * Returns 0 on success and fills out_args, on error returns appropriate
278 + * errno value.
279 + *
280 + * Caller is responsible to call of_node_put() on the returned out_args->np
281 + * pointer.
282 + *
283 + * Example::
284 + *
285 + * phandle1: node1 {
286 + * #list-cells = <2>;
287 + * };
288 + *
289 + * phandle2: node2 {
290 + * #list-cells = <1>;
291 + * };
292 + *
293 + * node3 {
294 + * list = <&phandle1 1 2 &phandle2 3>;
295 + * };
296 + *
297 + * To get a device_node of the ``node2`` node you may call this:
298 + * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
299 + */
300 +static inline int of_parse_phandle_with_args(const struct device_node *np,
301 + const char *list_name,
302 + const char *cells_name,
303 + int index,
304 + struct of_phandle_args *out_args)
305 +{
306 + int cell_count = -1;
307 +
308 + /* If cells_name is NULL we assume a cell count of 0 */
309 + if (!cells_name)
310 + cell_count = 0;
311 +
312 + return __of_parse_phandle_with_args(np, list_name, cells_name,
313 + cell_count, index, out_args);
314 +}
315 +
316 +/**
317 + * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
318 + * @np: pointer to a device tree node containing a list
319 + * @list_name: property name that contains a list
320 + * @cell_count: number of argument cells following the phandle
321 + * @index: index of a phandle to parse out
322 + * @out_args: optional pointer to output arguments structure (will be filled)
323 + *
324 + * This function is useful to parse lists of phandles and their arguments.
325 + * Returns 0 on success and fills out_args, on error returns appropriate
326 + * errno value.
327 + *
328 + * Caller is responsible to call of_node_put() on the returned out_args->np
329 + * pointer.
330 + *
331 + * Example::
332 + *
333 + * phandle1: node1 {
334 + * };
335 + *
336 + * phandle2: node2 {
337 + * };
338 + *
339 + * node3 {
340 + * list = <&phandle1 0 2 &phandle2 2 3>;
341 + * };
342 + *
343 + * To get a device_node of the ``node2`` node you may call this:
344 + * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
345 + */
346 +static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
347 + const char *list_name,
348 + int cell_count,
349 + int index,
350 + struct of_phandle_args *out_args)
351 +{
352 + return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
353 + index, out_args);
354 +}
355 +
356 +/**
357 * of_property_count_u8_elems - Count the number of u8 elements in a property
358 *
359 * @np: device node from which the property value is to be read.