Commit 6839fed0 authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Greg Kroah-Hartman

nvmem: core: remove global nvmem_cells_group

nvmem_cells_groups is a global variable that is also mutated.
This is complicated and error-prone.

Instead use a normal stack variable.
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20240705074852.423202-11-srinivas.kandagatla@linaro.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6188f233
...@@ -357,11 +357,6 @@ static const struct attribute_group nvmem_bin_group = { ...@@ -357,11 +357,6 @@ static const struct attribute_group nvmem_bin_group = {
.is_bin_visible = nvmem_bin_attr_is_visible, .is_bin_visible = nvmem_bin_attr_is_visible,
}; };
/* Cell attributes will be dynamically allocated */
static struct attribute_group nvmem_cells_group = {
.name = "cells",
};
static const struct attribute_group *nvmem_dev_groups[] = { static const struct attribute_group *nvmem_dev_groups[] = {
&nvmem_bin_group, &nvmem_bin_group,
NULL, NULL,
...@@ -424,23 +419,24 @@ static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, ...@@ -424,23 +419,24 @@ static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem,
static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
{ {
struct bin_attribute **cells_attrs, *attrs; struct attribute_group group = {
.name = "cells",
};
struct nvmem_cell_entry *entry; struct nvmem_cell_entry *entry;
struct bin_attribute *attrs;
unsigned int ncells = 0, i = 0; unsigned int ncells = 0, i = 0;
int ret = 0; int ret = 0;
mutex_lock(&nvmem_mutex); mutex_lock(&nvmem_mutex);
if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) { if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated)
nvmem_cells_group.bin_attrs = NULL;
goto unlock_mutex; goto unlock_mutex;
}
/* Allocate an array of attributes with a sentinel */ /* Allocate an array of attributes with a sentinel */
ncells = list_count_nodes(&nvmem->cells); ncells = list_count_nodes(&nvmem->cells);
cells_attrs = devm_kcalloc(&nvmem->dev, ncells + 1, group.bin_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
sizeof(struct bin_attribute *), GFP_KERNEL); sizeof(struct bin_attribute *), GFP_KERNEL);
if (!cells_attrs) { if (!group.bin_attrs) {
ret = -ENOMEM; ret = -ENOMEM;
goto unlock_mutex; goto unlock_mutex;
} }
...@@ -467,13 +463,11 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) ...@@ -467,13 +463,11 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
goto unlock_mutex; goto unlock_mutex;
} }
cells_attrs[i] = &attrs[i]; group.bin_attrs[i] = &attrs[i];
i++; i++;
} }
nvmem_cells_group.bin_attrs = cells_attrs; ret = device_add_group(&nvmem->dev, &group);
ret = device_add_group(&nvmem->dev, &nvmem_cells_group);
if (ret) if (ret)
goto unlock_mutex; goto unlock_mutex;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment