834-v6.8-0011-nvmem-u-boot-env-use-nvmem_add_one_cell-nvmem-subsys.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. From 7c8979b42b1a9c5604f431ba804928e55919263c Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Thu, 21 Dec 2023 18:34:18 +0100
  4. Subject: [PATCH] nvmem: u-boot-env: use nvmem_add_one_cell() nvmem subsystem
  5. helper
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. Simplify adding NVMEM cells.
  10. Signed-off-by: Rafał Miłecki <[email protected]>
  11. Reviewed-by: Miquel Raynal <[email protected]>
  12. Link: https://lore.kernel.org/r/[email protected]
  13. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  14. ---
  15. drivers/nvmem/u-boot-env.c | 55 +++++++++++++++-----------------------
  16. 1 file changed, 21 insertions(+), 34 deletions(-)
  17. --- a/drivers/nvmem/u-boot-env.c
  18. +++ b/drivers/nvmem/u-boot-env.c
  19. @@ -23,13 +23,10 @@ enum u_boot_env_format {
  20. struct u_boot_env {
  21. struct device *dev;
  22. + struct nvmem_device *nvmem;
  23. enum u_boot_env_format format;
  24. struct mtd_info *mtd;
  25. -
  26. - /* Cells */
  27. - struct nvmem_cell_info *cells;
  28. - int ncells;
  29. };
  30. struct u_boot_env_image_single {
  31. @@ -94,43 +91,36 @@ static int u_boot_env_read_post_process_
  32. static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf,
  33. size_t data_offset, size_t data_len)
  34. {
  35. + struct nvmem_device *nvmem = priv->nvmem;
  36. struct device *dev = priv->dev;
  37. char *data = buf + data_offset;
  38. char *var, *value, *eq;
  39. - int idx;
  40. -
  41. - priv->ncells = 0;
  42. - for (var = data; var < data + data_len && *var; var += strlen(var) + 1)
  43. - priv->ncells++;
  44. -
  45. - priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL);
  46. - if (!priv->cells)
  47. - return -ENOMEM;
  48. - for (var = data, idx = 0;
  49. + for (var = data;
  50. var < data + data_len && *var;
  51. - var = value + strlen(value) + 1, idx++) {
  52. + var = value + strlen(value) + 1) {
  53. + struct nvmem_cell_info info = {};
  54. +
  55. eq = strchr(var, '=');
  56. if (!eq)
  57. break;
  58. *eq = '\0';
  59. value = eq + 1;
  60. - priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL);
  61. - if (!priv->cells[idx].name)
  62. + info.name = devm_kstrdup(dev, var, GFP_KERNEL);
  63. + if (!info.name)
  64. return -ENOMEM;
  65. - priv->cells[idx].offset = data_offset + value - data;
  66. - priv->cells[idx].bytes = strlen(value);
  67. - priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name);
  68. + info.offset = data_offset + value - data;
  69. + info.bytes = strlen(value);
  70. + info.np = of_get_child_by_name(dev->of_node, info.name);
  71. if (!strcmp(var, "ethaddr")) {
  72. - priv->cells[idx].raw_len = strlen(value);
  73. - priv->cells[idx].bytes = ETH_ALEN;
  74. - priv->cells[idx].read_post_process = u_boot_env_read_post_process_ethaddr;
  75. + info.raw_len = strlen(value);
  76. + info.bytes = ETH_ALEN;
  77. + info.read_post_process = u_boot_env_read_post_process_ethaddr;
  78. }
  79. - }
  80. - if (WARN_ON(idx != priv->ncells))
  81. - priv->ncells = idx;
  82. + nvmem_add_one_cell(nvmem, &info);
  83. + }
  84. return 0;
  85. }
  86. @@ -209,7 +199,6 @@ static int u_boot_env_probe(struct platf
  87. struct device *dev = &pdev->dev;
  88. struct device_node *np = dev->of_node;
  89. struct u_boot_env *priv;
  90. - int err;
  91. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  92. if (!priv)
  93. @@ -224,17 +213,15 @@ static int u_boot_env_probe(struct platf
  94. return PTR_ERR(priv->mtd);
  95. }
  96. - err = u_boot_env_parse(priv);
  97. - if (err)
  98. - return err;
  99. -
  100. config.dev = dev;
  101. - config.cells = priv->cells;
  102. - config.ncells = priv->ncells;
  103. config.priv = priv;
  104. config.size = priv->mtd->size;
  105. - return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
  106. + priv->nvmem = devm_nvmem_register(dev, &config);
  107. + if (IS_ERR(priv->nvmem))
  108. + return PTR_ERR(priv->nvmem);
  109. +
  110. + return u_boot_env_parse(priv);
  111. }
  112. static const struct of_device_id u_boot_env_of_match_table[] = {