]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
of/fdt: Implement use BIN_ATTR_SIMPLE macro for fdt sysfs attribute
authorThomas Weißschuh <linux@weissschuh.net>
Fri, 22 Nov 2024 12:14:00 +0000 (13:14 +0100)
committerRob Herring (Arm) <robh@kernel.org>
Tue, 3 Dec 2024 16:52:41 +0000 (10:52 -0600)
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>
drivers/of/fdt.c

index 0121100372b41d44d841784b863af5492f19c31e..4b1e9f101ce34d7212cc8de99c7e7761a2636866 100644 (file)
@@ -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