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
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
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
17 drivers/of/base.c | 131 +++------------------------------------
18 include/linux/of.h | 148 ++++++++++++++++++++++++++++++++++++---------
19 2 files changed, 129 insertions(+), 150 deletions(-)
21 --- a/drivers/of/base.c
22 +++ b/drivers/of/base.c
23 @@ -1372,15 +1372,18 @@ int of_phandle_iterator_args(struct of_p
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)
38 struct of_phandle_iterator it;
39 int rc, cur_index = 0;
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) {
47 @@ -1423,82 +1426,7 @@ static int __of_parse_phandle_with_args(
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
59 - * Return: The device_node pointer with refcount incremented. Use
60 - * of_node_put() on it when done.
62 -struct device_node *of_parse_phandle(const struct device_node *np,
63 - const char *phandle_name, int index)
65 - struct of_phandle_args args;
70 - if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
76 -EXPORT_SYMBOL(of_parse_phandle);
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)
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
90 - * Caller is responsible to call of_node_put() on the returned out_args->np
96 - * #list-cells = <2>;
100 - * #list-cells = <1>;
104 - * list = <&phandle1 1 2 &phandle2 3>;
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);
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)
114 - int cell_count = -1;
119 - /* If cells_name is NULL we assume a cell count of 0 */
123 - return __of_parse_phandle_with_args(np, list_name, cells_name,
124 - cell_count, index, out_args);
126 -EXPORT_SYMBOL(of_parse_phandle_with_args);
127 +EXPORT_SYMBOL(__of_parse_phandle_with_args);
130 * of_parse_phandle_with_args_map() - Find a node pointed by phandle in a list and remap it
131 @@ -1685,47 +1613,6 @@ free:
132 EXPORT_SYMBOL(of_parse_phandle_with_args_map);
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)
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
146 - * Caller is responsible to call of_node_put() on the returned out_args->np
151 - * phandle1: node1 {
154 - * phandle2: node2 {
158 - * list = <&phandle1 0 2 &phandle2 2 3>;
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);
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)
170 - return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
173 -EXPORT_SYMBOL(of_parse_phandle_with_fixed_args);
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,
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);
203 @@ -857,18 +851,12 @@ static inline int of_property_read_strin
207 -static inline struct device_node *of_parse_phandle(const struct device_node *np,
208 - const char *phandle_name,
214 -static inline int of_parse_phandle_with_args(const struct device_node *np,
215 - const char *list_name,
216 - const char *cells_name,
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,
224 + struct of_phandle_args *out_args)
228 @@ -882,13 +870,6 @@ static inline int of_parse_phandle_with_
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)
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 @@ -1065,6 +1046,117 @@ static inline bool of_node_is_type(const
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
252 + * Return: The device_node pointer with refcount incremented. Use
253 + * of_node_put() on it when done.
255 +static inline struct device_node *of_parse_phandle(const struct device_node *np,
256 + const char *phandle_name,
259 + struct of_phandle_args args;
261 + if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
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)
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
280 + * Caller is responsible to call of_node_put() on the returned out_args->np
285 + * phandle1: node1 {
286 + * #list-cells = <2>;
289 + * phandle2: node2 {
290 + * #list-cells = <1>;
294 + * list = <&phandle1 1 2 &phandle2 3>;
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);
300 +static inline int of_parse_phandle_with_args(const struct device_node *np,
301 + const char *list_name,
302 + const char *cells_name,
304 + struct of_phandle_args *out_args)
306 + int cell_count = -1;
308 + /* If cells_name is NULL we assume a cell count of 0 */
312 + return __of_parse_phandle_with_args(np, list_name, cells_name,
313 + cell_count, index, out_args);
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)
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
328 + * Caller is responsible to call of_node_put() on the returned out_args->np
333 + * phandle1: node1 {
336 + * phandle2: node2 {
340 + * list = <&phandle1 0 2 &phandle2 2 3>;
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);
346 +static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
347 + const char *list_name,
350 + struct of_phandle_args *out_args)
352 + return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
357 * of_property_count_u8_elems - Count the number of u8 elements in a property
359 * @np: device node from which the property value is to be read.