1 From 7c8979b42b1a9c5604f431ba804928e55919263c Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Thu, 21 Dec 2023 18:34:18 +0100
4 Subject: [PATCH] nvmem: u-boot-env: use nvmem_add_one_cell() nvmem subsystem
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Simplify adding NVMEM cells.
12 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
13 Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
14 Link: https://lore.kernel.org/r/20231221173421.13737-3-zajec5@gmail.com
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17 drivers/nvmem/u-boot-env.c | 55 +++++++++++++++-----------------------
18 1 file changed, 21 insertions(+), 34 deletions(-)
20 --- a/drivers/nvmem/u-boot-env.c
21 +++ b/drivers/nvmem/u-boot-env.c
22 @@ -23,13 +23,10 @@ enum u_boot_env_format {
26 + struct nvmem_device *nvmem;
27 enum u_boot_env_format format;
32 - struct nvmem_cell_info *cells;
36 struct u_boot_env_image_single {
37 @@ -94,43 +91,36 @@ static int u_boot_env_read_post_process_
38 static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf,
39 size_t data_offset, size_t data_len)
41 + struct nvmem_device *nvmem = priv->nvmem;
42 struct device *dev = priv->dev;
43 char *data = buf + data_offset;
44 char *var, *value, *eq;
48 - for (var = data; var < data + data_len && *var; var += strlen(var) + 1)
51 - priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL);
55 - for (var = data, idx = 0;
57 var < data + data_len && *var;
58 - var = value + strlen(value) + 1, idx++) {
59 + var = value + strlen(value) + 1) {
60 + struct nvmem_cell_info info = {};
62 eq = strchr(var, '=');
68 - priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL);
69 - if (!priv->cells[idx].name)
70 + info.name = devm_kstrdup(dev, var, GFP_KERNEL);
73 - priv->cells[idx].offset = data_offset + value - data;
74 - priv->cells[idx].bytes = strlen(value);
75 - priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name);
76 + info.offset = data_offset + value - data;
77 + info.bytes = strlen(value);
78 + info.np = of_get_child_by_name(dev->of_node, info.name);
79 if (!strcmp(var, "ethaddr")) {
80 - priv->cells[idx].raw_len = strlen(value);
81 - priv->cells[idx].bytes = ETH_ALEN;
82 - priv->cells[idx].read_post_process = u_boot_env_read_post_process_ethaddr;
83 + info.raw_len = strlen(value);
84 + info.bytes = ETH_ALEN;
85 + info.read_post_process = u_boot_env_read_post_process_ethaddr;
89 - if (WARN_ON(idx != priv->ncells))
91 + nvmem_add_one_cell(nvmem, &info);
96 @@ -209,7 +199,6 @@ static int u_boot_env_probe(struct platf
97 struct device *dev = &pdev->dev;
98 struct device_node *np = dev->of_node;
99 struct u_boot_env *priv;
102 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
104 @@ -224,17 +213,15 @@ static int u_boot_env_probe(struct platf
105 return PTR_ERR(priv->mtd);
108 - err = u_boot_env_parse(priv);
113 - config.cells = priv->cells;
114 - config.ncells = priv->ncells;
116 config.size = priv->mtd->size;
118 - return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
119 + priv->nvmem = devm_nvmem_register(dev, &config);
120 + if (IS_ERR(priv->nvmem))
121 + return PTR_ERR(priv->nvmem);
123 + return u_boot_env_parse(priv);
126 static const struct of_device_id u_boot_env_of_match_table[] = {