819-v6.8-0008-nvmem-layouts-refactor-.add_cells-callback-arguments.patch 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. From 401df0d4f4098ecc9c5278da2f50756d62e5b37d Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Tue, 19 Dec 2023 13:01:03 +0100
  4. Subject: [PATCH] nvmem: layouts: refactor .add_cells() callback arguments
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Simply pass whole "struct nvmem_layout" instead of single variables.
  9. There is nothing in "struct nvmem_layout" that we have to hide from
  10. layout drivers. They also access it during .probe() and .remove().
  11. Thanks to this change:
  12. 1. API gets more consistent
  13. All layouts drivers callbacks get the same argument
  14. 2. Layouts get correct device
  15. Before this change NVMEM core code was passing NVMEM device instead
  16. of layout device. That resulted in:
  17. * Confusing prints
  18. * Calling devm_*() helpers on wrong device
  19. * Helpers like of_device_get_match_data() dereferencing NULLs
  20. 3. It gets possible to get match data
  21. First of all nvmem_layout_get_match_data() requires passing "struct
  22. nvmem_layout" which .add_cells() callback didn't have before this. It
  23. doesn't matter much as it's rather useless now anyway (and will be
  24. dropped).
  25. What's more important however is that of_device_get_match_data() can
  26. be used now thanks to owning a proper device pointer.
  27. Signed-off-by: Rafał Miłecki <[email protected]>
  28. Reviewed-by: Miquel Raynal <[email protected]>
  29. Reviewed-by: Michael Walle <[email protected]>
  30. Link: https://lore.kernel.org/r/[email protected]
  31. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  32. ---
  33. drivers/nvmem/core.c | 2 +-
  34. drivers/nvmem/layouts/onie-tlv.c | 4 +++-
  35. drivers/nvmem/layouts/sl28vpd.c | 4 +++-
  36. include/linux/nvmem-provider.h | 2 +-
  37. 4 files changed, 8 insertions(+), 4 deletions(-)
  38. --- a/drivers/nvmem/core.c
  39. +++ b/drivers/nvmem/core.c
  40. @@ -854,7 +854,7 @@ int nvmem_layout_register(struct nvmem_l
  41. return -EINVAL;
  42. /* Populate the cells */
  43. - ret = layout->add_cells(&layout->nvmem->dev, layout->nvmem);
  44. + ret = layout->add_cells(layout);
  45. if (ret)
  46. return ret;
  47. --- a/drivers/nvmem/layouts/onie-tlv.c
  48. +++ b/drivers/nvmem/layouts/onie-tlv.c
  49. @@ -182,8 +182,10 @@ static bool onie_tlv_crc_is_valid(struct
  50. return true;
  51. }
  52. -static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem)
  53. +static int onie_tlv_parse_table(struct nvmem_layout *layout)
  54. {
  55. + struct nvmem_device *nvmem = layout->nvmem;
  56. + struct device *dev = &layout->dev;
  57. struct onie_tlv_hdr hdr;
  58. size_t table_len, data_len, hdr_len;
  59. u8 *table, *data;
  60. --- a/drivers/nvmem/layouts/sl28vpd.c
  61. +++ b/drivers/nvmem/layouts/sl28vpd.c
  62. @@ -80,8 +80,10 @@ static int sl28vpd_v1_check_crc(struct d
  63. return 0;
  64. }
  65. -static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem)
  66. +static int sl28vpd_add_cells(struct nvmem_layout *layout)
  67. {
  68. + struct nvmem_device *nvmem = layout->nvmem;
  69. + struct device *dev = &layout->dev;
  70. const struct nvmem_cell_info *pinfo;
  71. struct nvmem_cell_info info = {0};
  72. struct device_node *layout_np;
  73. --- a/include/linux/nvmem-provider.h
  74. +++ b/include/linux/nvmem-provider.h
  75. @@ -173,7 +173,7 @@ struct nvmem_cell_table {
  76. struct nvmem_layout {
  77. struct device dev;
  78. struct nvmem_device *nvmem;
  79. - int (*add_cells)(struct device *dev, struct nvmem_device *nvmem);
  80. + int (*add_cells)(struct nvmem_layout *layout);
  81. };
  82. struct nvmem_layout_driver {