828-v6.4-0003-of-Rename-of_modalias_node.patch 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. From 673aa1ed1c9b6710bf24e3f0957d85e2f46c77db Mon Sep 17 00:00:00 2001
  2. From: Miquel Raynal <[email protected]>
  3. Date: Tue, 4 Apr 2023 18:21:16 +0100
  4. Subject: [PATCH] of: Rename of_modalias_node()
  5. This helper does not produce a real modalias, but tries to get the
  6. "product" compatible part of the "vendor,product" compatibles only. It
  7. is far from creating a purely useful modalias string and does not seem
  8. to be used like that directly anyway, so let's try to give this helper a
  9. more meaningful name before moving there a real modalias helper (already
  10. existing under of/device.c).
  11. Also update the various documentations to refer to the strings as
  12. "aliases" rather than "modaliases" which has a real meaning in the Linux
  13. kernel.
  14. There is no functional change.
  15. Cc: Rafael J. Wysocki <[email protected]>
  16. Cc: Len Brown <[email protected]>
  17. Cc: Maarten Lankhorst <[email protected]>
  18. Cc: Maxime Ripard <[email protected]>
  19. Cc: Thomas Zimmermann <[email protected]>
  20. Cc: Sebastian Reichel <[email protected]>
  21. Cc: Wolfram Sang <[email protected]>
  22. Cc: Mark Brown <[email protected]>
  23. Signed-off-by: Miquel Raynal <[email protected]>
  24. Reviewed-by: Rob Herring <[email protected]>
  25. Acked-by: Mark Brown <[email protected]>
  26. Signed-off-by: Srinivas Kandagatla <[email protected]>
  27. Acked-by: Sebastian Reichel <[email protected]>
  28. Link: https://lore.kernel.org/r/[email protected]
  29. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  30. ---
  31. drivers/acpi/bus.c | 7 ++++---
  32. drivers/gpu/drm/drm_mipi_dsi.c | 2 +-
  33. drivers/hsi/hsi_core.c | 2 +-
  34. drivers/i2c/busses/i2c-powermac.c | 2 +-
  35. drivers/i2c/i2c-core-of.c | 2 +-
  36. drivers/of/base.c | 18 +++++++++++-------
  37. drivers/spi/spi.c | 4 ++--
  38. include/linux/of.h | 3 ++-
  39. 8 files changed, 23 insertions(+), 17 deletions(-)
  40. --- a/drivers/acpi/bus.c
  41. +++ b/drivers/acpi/bus.c
  42. @@ -806,9 +806,10 @@ static bool acpi_of_modalias(struct acpi
  43. * @modalias: Pointer to buffer that modalias value will be copied into
  44. * @len: Length of modalias buffer
  45. *
  46. - * This is a counterpart of of_modalias_node() for struct acpi_device objects.
  47. - * If there is a compatible string for @adev, it will be copied to @modalias
  48. - * with the vendor prefix stripped; otherwise, @default_id will be used.
  49. + * This is a counterpart of of_alias_from_compatible() for struct acpi_device
  50. + * objects. If there is a compatible string for @adev, it will be copied to
  51. + * @modalias with the vendor prefix stripped; otherwise, @default_id will be
  52. + * used.
  53. */
  54. void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
  55. char *modalias, size_t len)
  56. --- a/drivers/gpu/drm/drm_mipi_dsi.c
  57. +++ b/drivers/gpu/drm/drm_mipi_dsi.c
  58. @@ -160,7 +160,7 @@ of_mipi_dsi_device_add(struct mipi_dsi_h
  59. int ret;
  60. u32 reg;
  61. - if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
  62. + if (of_alias_from_compatible(node, info.type, sizeof(info.type)) < 0) {
  63. drm_err(host, "modalias failure on %pOF\n", node);
  64. return ERR_PTR(-EINVAL);
  65. }
  66. --- a/drivers/hsi/hsi_core.c
  67. +++ b/drivers/hsi/hsi_core.c
  68. @@ -207,7 +207,7 @@ static void hsi_add_client_from_dt(struc
  69. if (!cl)
  70. return;
  71. - err = of_modalias_node(client, name, sizeof(name));
  72. + err = of_alias_from_compatible(client, name, sizeof(name));
  73. if (err)
  74. goto err;
  75. --- a/drivers/i2c/busses/i2c-powermac.c
  76. +++ b/drivers/i2c/busses/i2c-powermac.c
  77. @@ -284,7 +284,7 @@ static bool i2c_powermac_get_type(struct
  78. */
  79. /* First try proper modalias */
  80. - if (of_modalias_node(node, tmp, sizeof(tmp)) >= 0) {
  81. + if (of_alias_from_compatible(node, tmp, sizeof(tmp)) >= 0) {
  82. snprintf(type, type_size, "MAC,%s", tmp);
  83. return true;
  84. }
  85. --- a/drivers/i2c/i2c-core-of.c
  86. +++ b/drivers/i2c/i2c-core-of.c
  87. @@ -27,7 +27,7 @@ int of_i2c_get_board_info(struct device
  88. memset(info, 0, sizeof(*info));
  89. - if (of_modalias_node(node, info->type, sizeof(info->type)) < 0) {
  90. + if (of_alias_from_compatible(node, info->type, sizeof(info->type)) < 0) {
  91. dev_err(dev, "of_i2c: modalias failure on %pOF\n", node);
  92. return -EINVAL;
  93. }
  94. --- a/drivers/of/base.c
  95. +++ b/drivers/of/base.c
  96. @@ -1208,19 +1208,23 @@ struct device_node *of_find_matching_nod
  97. EXPORT_SYMBOL(of_find_matching_node_and_match);
  98. /**
  99. - * of_modalias_node - Lookup appropriate modalias for a device node
  100. + * of_alias_from_compatible - Lookup appropriate alias for a device node
  101. + * depending on compatible
  102. * @node: pointer to a device tree node
  103. - * @modalias: Pointer to buffer that modalias value will be copied into
  104. - * @len: Length of modalias value
  105. + * @alias: Pointer to buffer that alias value will be copied into
  106. + * @len: Length of alias value
  107. *
  108. * Based on the value of the compatible property, this routine will attempt
  109. - * to choose an appropriate modalias value for a particular device tree node.
  110. + * to choose an appropriate alias value for a particular device tree node.
  111. * It does this by stripping the manufacturer prefix (as delimited by a ',')
  112. * from the first entry in the compatible list property.
  113. *
  114. + * Note: The matching on just the "product" side of the compatible is a relic
  115. + * from I2C and SPI. Please do not add any new user.
  116. + *
  117. * Return: This routine returns 0 on success, <0 on failure.
  118. */
  119. -int of_modalias_node(struct device_node *node, char *modalias, int len)
  120. +int of_alias_from_compatible(const struct device_node *node, char *alias, int len)
  121. {
  122. const char *compatible, *p;
  123. int cplen;
  124. @@ -1229,10 +1233,10 @@ int of_modalias_node(struct device_node
  125. if (!compatible || strlen(compatible) > cplen)
  126. return -ENODEV;
  127. p = strchr(compatible, ',');
  128. - strscpy(modalias, p ? p + 1 : compatible, len);
  129. + strscpy(alias, p ? p + 1 : compatible, len);
  130. return 0;
  131. }
  132. -EXPORT_SYMBOL_GPL(of_modalias_node);
  133. +EXPORT_SYMBOL_GPL(of_alias_from_compatible);
  134. /**
  135. * of_find_node_by_phandle - Find a node given a phandle
  136. --- a/drivers/spi/spi.c
  137. +++ b/drivers/spi/spi.c
  138. @@ -2326,8 +2326,8 @@ of_register_spi_device(struct spi_contro
  139. }
  140. /* Select device driver */
  141. - rc = of_modalias_node(nc, spi->modalias,
  142. - sizeof(spi->modalias));
  143. + rc = of_alias_from_compatible(nc, spi->modalias,
  144. + sizeof(spi->modalias));
  145. if (rc < 0) {
  146. dev_err(&ctlr->dev, "cannot find modalias for %pOF\n", nc);
  147. goto err_out;
  148. --- a/include/linux/of.h
  149. +++ b/include/linux/of.h
  150. @@ -362,7 +362,8 @@ extern int of_n_addr_cells(struct device
  151. extern int of_n_size_cells(struct device_node *np);
  152. extern const struct of_device_id *of_match_node(
  153. const struct of_device_id *matches, const struct device_node *node);
  154. -extern int of_modalias_node(struct device_node *node, char *modalias, int len);
  155. +extern int of_alias_from_compatible(const struct device_node *node, char *alias,
  156. + int len);
  157. extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
  158. extern int __of_parse_phandle_with_args(const struct device_node *np,
  159. const char *list_name, const char *cells_name, int cell_count,