lkml.org 
[lkml]   [2020]   [May]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/2] nvmem: core: allow to register cells for existing device
Date
Current implementation does not allow to register nvmem cells for
existing device and requires that this will be done before device is
registered.

But there might a driver which provides only cells info which needs to
be added for already registered nvmem device.

Signed-off-by: Vadym Kochan <vadym.kochan@plvision.eu>
---
drivers/nvmem/core.c | 59 +++++++++++++++++++++++++++-----------------
1 file changed, 37 insertions(+), 22 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 05c6ae4b0b97..39c9df9ae9a0 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -482,35 +482,43 @@ int nvmem_unregister_notifier(struct notifier_block *nb)
}
EXPORT_SYMBOL_GPL(nvmem_unregister_notifier);

-static int nvmem_add_cells_from_table(struct nvmem_device *nvmem)
+static int __nvmem_add_cells_from_table(struct nvmem_device *nvmem,
+ struct nvmem_cell_table *table)
{
const struct nvmem_cell_info *info;
- struct nvmem_cell_table *table;
struct nvmem_cell *cell;
- int rval = 0, i;
+ int err, i;
+
+ for (i = 0; i < table->ncells; i++) {
+ info = &table->cells[i];
+
+ cell = kzalloc(sizeof(*cell), GFP_KERNEL);
+ if (!cell)
+ return -ENOMEM;
+
+ err = nvmem_cell_info_to_nvmem_cell(nvmem, info, cell);
+ if (err) {
+ kfree(cell);
+ return err;
+ }
+
+ nvmem_cell_add(cell);
+ }
+
+ return 0;
+}
+
+static int nvmem_add_cells_from_table(struct nvmem_device *nvmem)
+{
+ struct nvmem_cell_table *table;
+ int rval = 0;

mutex_lock(&nvmem_cell_mutex);
list_for_each_entry(table, &nvmem_cell_tables, node) {
if (strcmp(nvmem_dev_name(nvmem), table->nvmem_name) == 0) {
- for (i = 0; i < table->ncells; i++) {
- info = &table->cells[i];
-
- cell = kzalloc(sizeof(*cell), GFP_KERNEL);
- if (!cell) {
- rval = -ENOMEM;
- goto out;
- }
-
- rval = nvmem_cell_info_to_nvmem_cell(nvmem,
- info,
- cell);
- if (rval) {
- kfree(cell);
- goto out;
- }
-
- nvmem_cell_add(cell);
- }
+ rval = __nvmem_add_cells_from_table(nvmem, table);
+ if (rval)
+ goto out;
}
}

@@ -1560,6 +1568,13 @@ EXPORT_SYMBOL_GPL(nvmem_device_write);
*/
void nvmem_add_cell_table(struct nvmem_cell_table *table)
{
+ const char *dev_name = table->nvmem_name;
+ struct nvmem_device *nvmem;
+
+ nvmem = __nvmem_device_get((void *)dev_name, device_match_name);
+ if (nvmem)
+ __nvmem_add_cells_from_table(nvmem, table);
+
mutex_lock(&nvmem_cell_mutex);
list_add_tail(&table->node, &nvmem_cell_tables);
mutex_unlock(&nvmem_cell_mutex);
--
2.17.1
\
 
 \ /
  Last update: 2020-05-27 22:18    [W:0.081 / U:0.596 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site