We already link all nvmem devices into a linked list, but we don't export it for outside iteration.
Turn it into a class before exporting it. No functional change. Signed-off-by: Ahmad Fatoum <a.fat...@barebox.org> --- drivers/nvmem/core.c | 10 ++++------ include/linux/nvmem-consumer.h | 5 ++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 68cb27093227..253c00575d88 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -16,7 +16,6 @@ struct nvmem_device { const char *name; struct device dev; - struct list_head node; int stride; int word_size; int ncells; @@ -46,15 +45,14 @@ struct nvmem_cell { }; static LIST_HEAD(nvmem_cells); -static LIST_HEAD(nvmem_devs); +DEFINE_DEV_CLASS(nvmem_class, "nvmem"); void nvmem_devices_print(void) { struct nvmem_device *dev; - list_for_each_entry(dev, &nvmem_devs, node) { + class_for_each_container_of_device(&nvmem_class, dev, dev) printf("%s\n", dev_name(&dev->dev)); - } } static ssize_t nvmem_cdev_read(struct cdev *cdev, void *buf, size_t count, @@ -154,7 +152,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) if (!nvmem_np) return NULL; - list_for_each_entry(dev, &nvmem_devs, node) + class_for_each_container_of_device(&nvmem_class, dev, dev) if (dev->dev.of_node == nvmem_np) return dev; @@ -266,7 +264,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) } } - list_add_tail(&nvmem->node, &nvmem_devs); + class_add_device(&nvmem_class, &nvmem->dev); return nvmem; } diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 397c4c29dafd..c711b63aeeb0 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -12,7 +12,8 @@ #ifndef _LINUX_NVMEM_CONSUMER_H #define _LINUX_NVMEM_CONSUMER_H -struct device; +#include <device.h> + struct device_node; /* consumer cookie */ struct nvmem_cell; @@ -26,6 +27,8 @@ struct nvmem_cell_info { unsigned int nbits; }; +extern struct class nvmem_class; + #if IS_ENABLED(CONFIG_NVMEM) /* Cell based interface */ -- 2.39.5