Skip to content

Commit 6839fed

Browse files
t-8chgregkh
authored andcommitted
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: Thomas Weißschuh <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6188f23 commit 6839fed

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

drivers/nvmem/core.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,6 @@ static const struct attribute_group nvmem_bin_group = {
357357
.is_bin_visible = nvmem_bin_attr_is_visible,
358358
};
359359

360-
/* Cell attributes will be dynamically allocated */
361-
static struct attribute_group nvmem_cells_group = {
362-
.name = "cells",
363-
};
364-
365360
static const struct attribute_group *nvmem_dev_groups[] = {
366361
&nvmem_bin_group,
367362
NULL,
@@ -424,23 +419,24 @@ static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem,
424419

425420
static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
426421
{
427-
struct bin_attribute **cells_attrs, *attrs;
422+
struct attribute_group group = {
423+
.name = "cells",
424+
};
428425
struct nvmem_cell_entry *entry;
426+
struct bin_attribute *attrs;
429427
unsigned int ncells = 0, i = 0;
430428
int ret = 0;
431429

432430
mutex_lock(&nvmem_mutex);
433431

434-
if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) {
435-
nvmem_cells_group.bin_attrs = NULL;
432+
if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated)
436433
goto unlock_mutex;
437-
}
438434

439435
/* Allocate an array of attributes with a sentinel */
440436
ncells = list_count_nodes(&nvmem->cells);
441-
cells_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
442-
sizeof(struct bin_attribute *), GFP_KERNEL);
443-
if (!cells_attrs) {
437+
group.bin_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
438+
sizeof(struct bin_attribute *), GFP_KERNEL);
439+
if (!group.bin_attrs) {
444440
ret = -ENOMEM;
445441
goto unlock_mutex;
446442
}
@@ -467,13 +463,11 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
467463
goto unlock_mutex;
468464
}
469465

470-
cells_attrs[i] = &attrs[i];
466+
group.bin_attrs[i] = &attrs[i];
471467
i++;
472468
}
473469

474-
nvmem_cells_group.bin_attrs = cells_attrs;
475-
476-
ret = device_add_group(&nvmem->dev, &nvmem_cells_group);
470+
ret = device_add_group(&nvmem->dev, &group);
477471
if (ret)
478472
goto unlock_mutex;
479473

0 commit comments

Comments
 (0)