drivers/of/fdt.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
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>
---
drivers/of/fdt.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 0121100372b41d44d841784b863af5492f19c31e..4b1e9f101ce34d7212cc8de99c7e7761a2636866 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1264,18 +1264,9 @@ void __init unflatten_and_copy_device_tree(void)
}
#ifdef CONFIG_SYSFS
-static ssize_t of_fdt_raw_read(struct file *filp, struct kobject *kobj,
- struct bin_attribute *bin_attr,
- char *buf, loff_t off, size_t count)
-{
- memcpy(buf, initial_boot_params + off, count);
- return count;
-}
-
static int __init of_fdt_raw_init(void)
{
- static struct bin_attribute of_fdt_raw_attr =
- __BIN_ATTR(fdt, S_IRUSR, of_fdt_raw_read, NULL, 0);
+ static __ro_after_init BIN_ATTR_SIMPLE_ADMIN_RO(fdt);
if (!initial_boot_params)
return 0;
@@ -1285,8 +1276,9 @@ static int __init of_fdt_raw_init(void)
pr_warn("not creating '/sys/firmware/fdt': CRC check failed\n");
return 0;
}
- of_fdt_raw_attr.size = fdt_totalsize(initial_boot_params);
- return sysfs_create_bin_file(firmware_kobj, &of_fdt_raw_attr);
+ bin_attr_fdt.private = initial_boot_params;
+ bin_attr_fdt.size = fdt_totalsize(initial_boot_params);
+ return sysfs_create_bin_file(firmware_kobj, &bin_attr_fdt);
}
late_initcall(of_fdt_raw_init);
#endif
---
base-commit: 28eb75e178d389d325f1666e422bc13bbbb9804c
change-id: 20241122-sysfs-const-bin_attr-of-7765932a946d
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
On Fri, 22 Nov 2024 13:14:00 +0100, Thomas Weißschuh wrote: > 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> > --- > drivers/of/fdt.c | 16 ++++------------ > 1 file changed, 4 insertions(+), 12 deletions(-) > Applied, thanks!
© 2016 - 2026 Red Hat, Inc.