826-v5.17-of-base-make-small-of_parse_phandle-variants-static-.patch 12 KB

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