kheaders: Simplify attribute through __BIN_ATTR_SIMPLE_RO()
authorThomas Weißschuh <linux@weissschuh.net>
Sat, 21 Dec 2024 14:09:34 +0000 (15:09 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Dec 2024 08:46:49 +0000 (09:46 +0100)
The utility macro from the sysfs core is sufficient to implement this
attribute. Make use of it.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20241221-sysfs-const-bin_attr-kheaders-v2-1-8205538aa012@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/kheaders.c

index 42163c9e94e557c5043e2ac7987b567f23087ee2..378088b07f46d643736c04b9075f631e0dc2a53d 100644 (file)
@@ -29,25 +29,12 @@ asm (
 extern char kernel_headers_data[];
 extern char kernel_headers_data_end[];
 
-static ssize_t
-ikheaders_read(struct file *file,  struct kobject *kobj,
-              struct bin_attribute *bin_attr,
-              char *buf, loff_t off, size_t len)
-{
-       memcpy(buf, &kernel_headers_data[off], len);
-       return len;
-}
-
-static struct bin_attribute kheaders_attr __ro_after_init = {
-       .attr = {
-               .name = "kheaders.tar.xz",
-               .mode = 0444,
-       },
-       .read = &ikheaders_read,
-};
+static struct bin_attribute kheaders_attr __ro_after_init =
+       __BIN_ATTR_SIMPLE_RO(kheaders.tar.xz, 0444);
 
 static int __init ikheaders_init(void)
 {
+       kheaders_attr.private = kernel_headers_data;
        kheaders_attr.size = (kernel_headers_data_end -
                              kernel_headers_data);
        return sysfs_create_bin_file(kernel_kobj, &kheaders_attr);