1 From 2ded6830d376d5e7bf43d59f7f7fdf1a59abc676 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Mon, 6 Feb 2023 13:43:49 +0000
4 Subject: [PATCH] nvmem: core: add nvmem_add_one_cell()
6 Add a new function to add exactly one cell. This will be used by the
7 nvmem layout drivers to add custom cells. In contrast to the
8 nvmem_add_cells(), this has the advantage that we don't have to assemble
9 a list of cells on runtime.
11 Signed-off-by: Michael Walle <michael@walle.cc>
12 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
13 Link: https://lore.kernel.org/r/20230206134356.839737-16-srinivas.kandagatla@linaro.org
14 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 drivers/nvmem/core.c | 59 ++++++++++++++++++++--------------
17 include/linux/nvmem-provider.h | 8 +++++
18 2 files changed, 43 insertions(+), 24 deletions(-)
20 --- a/drivers/nvmem/core.c
21 +++ b/drivers/nvmem/core.c
22 @@ -502,6 +502,36 @@ static int nvmem_cell_info_to_nvmem_cell
26 + * nvmem_add_one_cell() - Add one cell information to an nvmem device
28 + * @nvmem: nvmem device to add cells to.
29 + * @info: nvmem cell info to add to the device
31 + * Return: 0 or negative error code on failure.
33 +int nvmem_add_one_cell(struct nvmem_device *nvmem,
34 + const struct nvmem_cell_info *info)
36 + struct nvmem_cell_entry *cell;
39 + cell = kzalloc(sizeof(*cell), GFP_KERNEL);
43 + rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell);
49 + nvmem_cell_entry_add(cell);
53 +EXPORT_SYMBOL_GPL(nvmem_add_one_cell);
56 * nvmem_add_cells() - Add cell information to an nvmem device
58 * @nvmem: nvmem device to add cells to.
59 @@ -514,34 +544,15 @@ static int nvmem_add_cells(struct nvmem_
60 const struct nvmem_cell_info *info,
63 - struct nvmem_cell_entry **cells;
66 - cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
71 for (i = 0; i < ncells; i++) {
72 - cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
78 - rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]);
84 - nvmem_cell_entry_add(cells[i]);
85 + rval = nvmem_add_one_cell(nvmem, &info[i]);
91 - /* remove tmp array */
99 --- a/include/linux/nvmem-provider.h
100 +++ b/include/linux/nvmem-provider.h
101 @@ -155,6 +155,9 @@ struct nvmem_device *devm_nvmem_register
102 void nvmem_add_cell_table(struct nvmem_cell_table *table);
103 void nvmem_del_cell_table(struct nvmem_cell_table *table);
105 +int nvmem_add_one_cell(struct nvmem_device *nvmem,
106 + const struct nvmem_cell_info *info);
110 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
111 @@ -172,6 +175,11 @@ devm_nvmem_register(struct device *dev,
113 static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
114 static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
115 +static inline int nvmem_add_one_cell(struct nvmem_device *nvmem,
116 + const struct nvmem_cell_info *info)
118 + return -EOPNOTSUPP;
121 #endif /* CONFIG_NVMEM */
122 #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */