lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241122-sysfs-const-bin_attr-of-v1-1-7052f9dcd4be@weissschuh.net>
Date: Fri, 22 Nov 2024 13:14:00 +0100
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Rob Herring <robh@...nel.org>, Saravana Kannan <saravanak@...gle.com>
Cc: devicetree@...r.kernel.org, linux-kernel@...r.kernel.org, 
 Thomas Weißschuh <linux@...ssschuh.net>
Subject: [PATCH] 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@...ssschuh.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@...ssschuh.net>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ