Skip to content

Commit d8959b9

Browse files
t-8chpetrpavlu
authored andcommitted
module: sysfs: Drop member 'module_sect_attrs::nsections'
The member is only used to iterate over all attributes in free_sect_attrs(). However the attribute group can already be used for that. Use the group and drop 'nsections'. Signed-off-by: Thomas Weißschuh <[email protected]> Reviewed-by: Petr Pavlu <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/20241227-sysfs-const-bin_attr-module-v2-1-e267275f0f37@weissschuh.net Signed-off-by: Petr Pavlu <[email protected]>
1 parent f3227ff commit d8959b9

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

kernel/module/sysfs.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct module_sect_attr {
2626

2727
struct module_sect_attrs {
2828
struct attribute_group grp;
29-
unsigned int nsections;
3029
struct module_sect_attr attrs[];
3130
};
3231

@@ -62,10 +61,10 @@ static ssize_t module_sect_read(struct file *file, struct kobject *kobj,
6261

6362
static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
6463
{
65-
unsigned int section;
64+
struct bin_attribute **bin_attr;
6665

67-
for (section = 0; section < sect_attrs->nsections; section++)
68-
kfree(sect_attrs->attrs[section].battr.attr.name);
66+
for (bin_attr = sect_attrs->grp.bin_attrs; *bin_attr; bin_attr++)
67+
kfree((*bin_attr)->attr.name);
6968
kfree(sect_attrs);
7069
}
7170

@@ -92,7 +91,6 @@ static int add_sect_attrs(struct module *mod, const struct load_info *info)
9291
sect_attrs->grp.name = "sections";
9392
sect_attrs->grp.bin_attrs = (void *)sect_attrs + size[0];
9493

95-
sect_attrs->nsections = 0;
9694
sattr = &sect_attrs->attrs[0];
9795
gattr = &sect_attrs->grp.bin_attrs[0];
9896
for (i = 0; i < info->hdr->e_shnum; i++) {
@@ -108,7 +106,6 @@ static int add_sect_attrs(struct module *mod, const struct load_info *info)
108106
ret = -ENOMEM;
109107
goto out;
110108
}
111-
sect_attrs->nsections++;
112109
sattr->battr.read = module_sect_read;
113110
sattr->battr.size = MODULE_SECT_READ_SIZE;
114111
sattr->battr.attr.mode = 0400;

0 commit comments

Comments
 (0)