[PATCH v7 3/7] nvmem: core: Track the registered devices

Miquel Raynal posted 7 patches 2 years, 6 months ago
There is a newer version of this series
[PATCH v7 3/7] nvmem: core: Track the registered devices
Posted by Miquel Raynal 2 years, 6 months ago
Create a list with all the NVMEM devices registered in the
subsystem. This way we can iterate through them when needed (unused for
now).

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 257328887263..4e81e0aaf433 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -23,6 +23,7 @@
 struct nvmem_device {
 	struct module		*owner;
 	struct device		dev;
+	struct list_head	node;
 	int			stride;
 	int			word_size;
 	int			id;
@@ -76,6 +77,9 @@ static LIST_HEAD(nvmem_cell_tables);
 static DEFINE_MUTEX(nvmem_lookup_mutex);
 static LIST_HEAD(nvmem_lookup_list);
 
+static DEFINE_MUTEX(nvmem_devices_mutex);
+static LIST_HEAD(nvmem_devices_list);
+
 static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
 
 static DEFINE_SPINLOCK(nvmem_layout_lock);
@@ -1012,6 +1016,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (rval)
 		goto err_remove_cells;
 
+	mutex_lock(&nvmem_devices_mutex);
+	list_add_tail(&nvmem->node, &nvmem_devices_list);
+	mutex_unlock(&nvmem_devices_mutex);
+
 	blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
 
 	return nvmem;
@@ -1037,6 +1045,10 @@ static void nvmem_device_release(struct kref *kref)
 
 	blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem);
 
+	mutex_lock(&nvmem_devices_mutex);
+	list_del(&nvmem->node);
+	mutex_unlock(&nvmem_devices_mutex);
+
 	if (nvmem->flags & FLAG_COMPAT)
 		device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
 
-- 
2.34.1