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.

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 <gregkh@linuxfoundation.org>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20241121-sysfs-const-bin_attr-ksysfs-v1-1-972faced149d@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
0f9e1f3a e1a51c2b

+4 -17
+4 -17
kernel/ksysfs.c
··· 239 239 extern const void __stop_notes; 240 240 #define notes_size (&__stop_notes - &__start_notes) 241 241 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); 257 243 258 244 struct kobject *kernel_kobj; 259 245 EXPORT_SYMBOL_GPL(kernel_kobj); ··· 293 307 goto kset_exit; 294 308 295 309 if (notes_size > 0) { 296 - notes_attr.size = notes_size; 297 - error = sysfs_create_bin_file(kernel_kobj, &notes_attr); 310 + bin_attr_notes.private = (void *)&__start_notes; 311 + bin_attr_notes.size = notes_size; 312 + error = sysfs_create_bin_file(kernel_kobj, &bin_attr_notes); 298 313 if (error) 299 314 goto group_exit; 300 315 }