Skip to content

Commit 0f9e1f3

Browse files
t-8chgregkh
authored andcommitted
kernel/ksysfs.c: simplify bin_attribute definition
The notes attribute can be implemented in terms of BIN_ATTR_SIMPLE(). This saves memory at runtime and is a preparation for the constification of struct bin_attribute. Cc: Greg Kroah-Hartman <[email protected]> Signed-off-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/r/20241121-sysfs-const-bin_attr-ksysfs-v1-1-972faced149d@weissschuh.net Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e1a51c2 commit 0f9e1f3

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

kernel/ksysfs.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,7 @@ extern const void __start_notes;
239239
extern const void __stop_notes;
240240
#define notes_size (&__stop_notes - &__start_notes)
241241

242-
static ssize_t notes_read(struct file *filp, struct kobject *kobj,
243-
struct bin_attribute *bin_attr,
244-
char *buf, loff_t off, size_t count)
245-
{
246-
memcpy(buf, &__start_notes + off, count);
247-
return count;
248-
}
249-
250-
static struct bin_attribute notes_attr __ro_after_init = {
251-
.attr = {
252-
.name = "notes",
253-
.mode = S_IRUGO,
254-
},
255-
.read = &notes_read,
256-
};
242+
static __ro_after_init BIN_ATTR_SIMPLE_RO(notes);
257243

258244
struct kobject *kernel_kobj;
259245
EXPORT_SYMBOL_GPL(kernel_kobj);
@@ -307,8 +293,9 @@ static int __init ksysfs_init(void)
307293
goto kset_exit;
308294

309295
if (notes_size > 0) {
310-
notes_attr.size = notes_size;
311-
error = sysfs_create_bin_file(kernel_kobj, &notes_attr);
296+
bin_attr_notes.private = (void *)&__start_notes;
297+
bin_attr_notes.size = notes_size;
298+
error = sysfs_create_bin_file(kernel_kobj, &bin_attr_notes);
312299
if (error)
313300
goto group_exit;
314301
}

0 commit comments

Comments
 (0)