Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <linux@weissschuh.net>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20240705074852.423202-11-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
6839fed0 6188f233

+10 -16
+10 -16
drivers/nvmem/core.c
··· 357 357 .is_bin_visible = nvmem_bin_attr_is_visible, 358 358 }; 359 359 360 - /* Cell attributes will be dynamically allocated */ 361 - static struct attribute_group nvmem_cells_group = { 362 - .name = "cells", 363 - }; 364 - 365 360 static const struct attribute_group *nvmem_dev_groups[] = { 366 361 &nvmem_bin_group, 367 362 NULL, ··· 419 424 420 425 static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) 421 426 { 422 - struct bin_attribute **cells_attrs, *attrs; 427 + struct attribute_group group = { 428 + .name = "cells", 429 + }; 423 430 struct nvmem_cell_entry *entry; 431 + struct bin_attribute *attrs; 424 432 unsigned int ncells = 0, i = 0; 425 433 int ret = 0; 426 434 427 435 mutex_lock(&nvmem_mutex); 428 436 429 - if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) { 430 - nvmem_cells_group.bin_attrs = NULL; 437 + if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) 431 438 goto unlock_mutex; 432 - } 433 439 434 440 /* Allocate an array of attributes with a sentinel */ 435 441 ncells = list_count_nodes(&nvmem->cells); 436 - cells_attrs = devm_kcalloc(&nvmem->dev, ncells + 1, 437 - sizeof(struct bin_attribute *), GFP_KERNEL); 438 - if (!cells_attrs) { 442 + group.bin_attrs = devm_kcalloc(&nvmem->dev, ncells + 1, 443 + sizeof(struct bin_attribute *), GFP_KERNEL); 444 + if (!group.bin_attrs) { 439 445 ret = -ENOMEM; 440 446 goto unlock_mutex; 441 447 } ··· 463 467 goto unlock_mutex; 464 468 } 465 469 466 - cells_attrs[i] = &attrs[i]; 470 + group.bin_attrs[i] = &attrs[i]; 467 471 i++; 468 472 } 469 473 470 - nvmem_cells_group.bin_attrs = cells_attrs; 471 - 472 - ret = device_add_group(&nvmem->dev, &nvmem_cells_group); 474 + ret = device_add_group(&nvmem->dev, &group); 473 475 if (ret) 474 476 goto unlock_mutex; 475 477