828-v6.4-0004-of-Move-of_modalias-to-module.c.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. From bd7a7ed774afd1a4174df34227626c95573be517 Mon Sep 17 00:00:00 2001
  2. From: Miquel Raynal <[email protected]>
  3. Date: Tue, 4 Apr 2023 18:21:17 +0100
  4. Subject: [PATCH] of: Move of_modalias() to module.c
  5. Create a specific .c file for OF related module handling.
  6. Move of_modalias() inside as a first step.
  7. The helper is exposed through of.h even though it is only used by core
  8. files because the users from device.c will soon be split into an OF-only
  9. helper in module.c as well as a device-oriented inline helper in
  10. of_device.h. Putting this helper in of_private.h would require to
  11. include of_private.h from of_device.h, which is not acceptable.
  12. Suggested-by: Rob Herring <[email protected]>
  13. Signed-off-by: Miquel Raynal <[email protected]>
  14. Reviewed-by: Rob Herring <[email protected]>
  15. Signed-off-by: Srinivas Kandagatla <[email protected]>
  16. Link: https://lore.kernel.org/r/[email protected]
  17. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  18. ---
  19. drivers/of/Makefile | 2 +-
  20. drivers/of/device.c | 37 -------------------------------------
  21. drivers/of/module.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
  22. include/linux/of.h | 9 +++++++++
  23. 4 files changed, 54 insertions(+), 38 deletions(-)
  24. create mode 100644 drivers/of/module.c
  25. --- a/drivers/of/Makefile
  26. +++ b/drivers/of/Makefile
  27. @@ -1,5 +1,5 @@
  28. # SPDX-License-Identifier: GPL-2.0
  29. -obj-y = base.o device.o platform.o property.o
  30. +obj-y = base.o device.o module.o platform.o property.o
  31. obj-$(CONFIG_OF_KOBJ) += kobj.o
  32. obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
  33. obj-$(CONFIG_OF_FLATTREE) += fdt.o
  34. --- a/drivers/of/device.c
  35. +++ b/drivers/of/device.c
  36. @@ -1,5 +1,4 @@
  37. // SPDX-License-Identifier: GPL-2.0
  38. -#include <linux/string.h>
  39. #include <linux/kernel.h>
  40. #include <linux/of.h>
  41. #include <linux/of_device.h>
  42. @@ -241,42 +240,6 @@ const void *of_device_get_match_data(con
  43. }
  44. EXPORT_SYMBOL(of_device_get_match_data);
  45. -static ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
  46. -{
  47. - const char *compat;
  48. - char *c;
  49. - struct property *p;
  50. - ssize_t csize;
  51. - ssize_t tsize;
  52. -
  53. - /* Name & Type */
  54. - /* %p eats all alphanum characters, so %c must be used here */
  55. - csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
  56. - of_node_get_device_type(np));
  57. - tsize = csize;
  58. - len -= csize;
  59. - if (str)
  60. - str += csize;
  61. -
  62. - of_property_for_each_string(np, "compatible", p, compat) {
  63. - csize = strlen(compat) + 1;
  64. - tsize += csize;
  65. - if (csize > len)
  66. - continue;
  67. -
  68. - csize = snprintf(str, len, "C%s", compat);
  69. - for (c = str; c; ) {
  70. - c = strchr(c, ' ');
  71. - if (c)
  72. - *c++ = '_';
  73. - }
  74. - len -= csize;
  75. - str += csize;
  76. - }
  77. -
  78. - return tsize;
  79. -}
  80. -
  81. int of_device_request_module(struct device *dev)
  82. {
  83. char *str;
  84. --- /dev/null
  85. +++ b/drivers/of/module.c
  86. @@ -0,0 +1,44 @@
  87. +// SPDX-License-Identifier: GPL-2.0
  88. +/*
  89. + * Linux kernel module helpers.
  90. + */
  91. +
  92. +#include <linux/of.h>
  93. +#include <linux/slab.h>
  94. +#include <linux/string.h>
  95. +
  96. +ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
  97. +{
  98. + const char *compat;
  99. + char *c;
  100. + struct property *p;
  101. + ssize_t csize;
  102. + ssize_t tsize;
  103. +
  104. + /* Name & Type */
  105. + /* %p eats all alphanum characters, so %c must be used here */
  106. + csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
  107. + of_node_get_device_type(np));
  108. + tsize = csize;
  109. + len -= csize;
  110. + if (str)
  111. + str += csize;
  112. +
  113. + of_property_for_each_string(np, "compatible", p, compat) {
  114. + csize = strlen(compat) + 1;
  115. + tsize += csize;
  116. + if (csize > len)
  117. + continue;
  118. +
  119. + csize = snprintf(str, len, "C%s", compat);
  120. + for (c = str; c; ) {
  121. + c = strchr(c, ' ');
  122. + if (c)
  123. + *c++ = '_';
  124. + }
  125. + len -= csize;
  126. + str += csize;
  127. + }
  128. +
  129. + return tsize;
  130. +}
  131. --- a/include/linux/of.h
  132. +++ b/include/linux/of.h
  133. @@ -373,6 +373,9 @@ extern int of_parse_phandle_with_args_ma
  134. extern int of_count_phandle_with_args(const struct device_node *np,
  135. const char *list_name, const char *cells_name);
  136. +/* module functions */
  137. +extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len);
  138. +
  139. /* phandle iterator functions */
  140. extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
  141. const struct device_node *np,
  142. @@ -735,6 +738,12 @@ static inline int of_count_phandle_with_
  143. return -ENOSYS;
  144. }
  145. +static inline ssize_t of_modalias(const struct device_node *np, char *str,
  146. + ssize_t len)
  147. +{
  148. + return -ENODEV;
  149. +}
  150. +
  151. static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
  152. const struct device_node *np,
  153. const char *list_name,