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.

of/fdt: Implement use BIN_ATTR_SIMPLE macro for fdt sysfs attribute

The usage of the macro allows to remove the custom handler function,
saving some memory. Additionally the code is easier to read.

While at it also mark the attribute as __ro_after_init, as the only
modification happens in the __init phase.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20241122-sysfs-const-bin_attr-of-v1-1-7052f9dcd4be@weissschuh.net
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

authored by

Thomas Weißschuh and committed by
Rob Herring (Arm)
16ef9c9d 40384c84

+4 -12
+4 -12
drivers/of/fdt.c
··· 1264 1264 } 1265 1265 1266 1266 #ifdef CONFIG_SYSFS 1267 - static ssize_t of_fdt_raw_read(struct file *filp, struct kobject *kobj, 1268 - struct bin_attribute *bin_attr, 1269 - char *buf, loff_t off, size_t count) 1270 - { 1271 - memcpy(buf, initial_boot_params + off, count); 1272 - return count; 1273 - } 1274 - 1275 1267 static int __init of_fdt_raw_init(void) 1276 1268 { 1277 - static struct bin_attribute of_fdt_raw_attr = 1278 - __BIN_ATTR(fdt, S_IRUSR, of_fdt_raw_read, NULL, 0); 1269 + static __ro_after_init BIN_ATTR_SIMPLE_ADMIN_RO(fdt); 1279 1270 1280 1271 if (!initial_boot_params) 1281 1272 return 0; ··· 1276 1285 pr_warn("not creating '/sys/firmware/fdt': CRC check failed\n"); 1277 1286 return 0; 1278 1287 } 1279 - of_fdt_raw_attr.size = fdt_totalsize(initial_boot_params); 1280 - return sysfs_create_bin_file(firmware_kobj, &of_fdt_raw_attr); 1288 + bin_attr_fdt.private = initial_boot_params; 1289 + bin_attr_fdt.size = fdt_totalsize(initial_boot_params); 1290 + return sysfs_create_bin_file(firmware_kobj, &bin_attr_fdt); 1281 1291 } 1282 1292 late_initcall(of_fdt_raw_init); 1283 1293 #endif