Skip to content

Commit 66bc1a1

Browse files
l1kgregkh
authored andcommitted
treewide: Use sysfs_bin_attr_simple_read() helper
Deduplicate ->read() callbacks of bin_attributes which are backed by a simple buffer in memory: Use the newly introduced sysfs_bin_attr_simple_read() helper instead, either by referencing it directly or by declaring such bin_attributes with BIN_ATTR_SIMPLE_RO() or BIN_ATTR_SIMPLE_ADMIN_RO(). Aside from a reduction of LoC, this shaves off a few bytes from vmlinux (304 bytes on an x86_64 allyesconfig). No functional change intended. Signed-off-by: Lukas Wunner <[email protected]> Acked-by: Zhi Wang <[email protected]> Acked-by: Michael Ellerman <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/92ee0a0e83a5a3f3474845db6c8575297698933a.1712410202.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d48c031 commit 66bc1a1

File tree

8 files changed

+14
-85
lines changed

8 files changed

+14
-85
lines changed

arch/powerpc/platforms/powernv/opal.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,6 @@ static int __init opal_sysfs_init(void)
792792
return 0;
793793
}
794794

795-
static ssize_t export_attr_read(struct file *fp, struct kobject *kobj,
796-
struct bin_attribute *bin_attr, char *buf,
797-
loff_t off, size_t count)
798-
{
799-
return memory_read_from_buffer(buf, count, &off, bin_attr->private,
800-
bin_attr->size);
801-
}
802-
803795
static int opal_add_one_export(struct kobject *parent, const char *export_name,
804796
struct device_node *np, const char *prop_name)
805797
{
@@ -826,7 +818,7 @@ static int opal_add_one_export(struct kobject *parent, const char *export_name,
826818
sysfs_bin_attr_init(attr);
827819
attr->attr.name = name;
828820
attr->attr.mode = 0400;
829-
attr->read = export_attr_read;
821+
attr->read = sysfs_bin_attr_simple_read;
830822
attr->private = __va(vals[0]);
831823
attr->size = vals[1];
832824

drivers/acpi/bgrt.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ BGRT_SHOW(type, image_type);
2929
BGRT_SHOW(xoffset, image_offset_x);
3030
BGRT_SHOW(yoffset, image_offset_y);
3131

32-
static ssize_t image_read(struct file *file, struct kobject *kobj,
33-
struct bin_attribute *attr, char *buf, loff_t off, size_t count)
34-
{
35-
memcpy(buf, attr->private + off, count);
36-
return count;
37-
}
38-
39-
static BIN_ATTR_RO(image, 0); /* size gets filled in later */
32+
static BIN_ATTR_SIMPLE_RO(image);
4033

4134
static struct attribute *bgrt_attributes[] = {
4235
&bgrt_attr_version.attr,

drivers/firmware/dmi_scan.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -746,16 +746,8 @@ static void __init dmi_scan_machine(void)
746746
pr_info("DMI not present or invalid.\n");
747747
}
748748

749-
static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
750-
struct bin_attribute *attr, char *buf,
751-
loff_t pos, size_t count)
752-
{
753-
memcpy(buf, attr->private + pos, count);
754-
return count;
755-
}
756-
757-
static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0);
758-
static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0);
749+
static BIN_ATTR_SIMPLE_ADMIN_RO(smbios_entry_point);
750+
static BIN_ATTR_SIMPLE_ADMIN_RO(DMI);
759751

760752
static int __init dmi_init(void)
761753
{

drivers/firmware/efi/rci2-table.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@ static u8 *rci2_base;
4040
static u32 rci2_table_len;
4141
unsigned long rci2_table_phys __ro_after_init = EFI_INVALID_TABLE_ADDR;
4242

43-
static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
44-
struct bin_attribute *attr, char *buf,
45-
loff_t pos, size_t count)
46-
{
47-
memcpy(buf, attr->private + pos, count);
48-
return count;
49-
}
50-
51-
static BIN_ATTR(rci2, S_IRUSR, raw_table_read, NULL, 0);
43+
static BIN_ATTR_SIMPLE_ADMIN_RO(rci2);
5244

5345
static u16 checksum(void)
5446
{

drivers/gpu/drm/i915/gvt/firmware.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,7 @@ struct gvt_firmware_header {
5050

5151
#define dev_to_drm_minor(d) dev_get_drvdata((d))
5252

53-
static ssize_t
54-
gvt_firmware_read(struct file *filp, struct kobject *kobj,
55-
struct bin_attribute *attr, char *buf,
56-
loff_t offset, size_t count)
57-
{
58-
memcpy(buf, attr->private + offset, count);
59-
return count;
60-
}
61-
62-
static struct bin_attribute firmware_attr = {
63-
.attr = {.name = "gvt_firmware", .mode = (S_IRUSR)},
64-
.read = gvt_firmware_read,
65-
.write = NULL,
66-
.mmap = NULL,
67-
};
53+
static BIN_ATTR_SIMPLE_ADMIN_RO(gvt_firmware);
6854

6955
static int expose_firmware_sysfs(struct intel_gvt *gvt)
7056
{
@@ -107,10 +93,10 @@ static int expose_firmware_sysfs(struct intel_gvt *gvt)
10793
crc32_start = offsetof(struct gvt_firmware_header, version);
10894
h->crc32 = crc32_le(0, firmware + crc32_start, size - crc32_start);
10995

110-
firmware_attr.size = size;
111-
firmware_attr.private = firmware;
96+
bin_attr_gvt_firmware.size = size;
97+
bin_attr_gvt_firmware.private = firmware;
11298

113-
ret = device_create_bin_file(&pdev->dev, &firmware_attr);
99+
ret = device_create_bin_file(&pdev->dev, &bin_attr_gvt_firmware);
114100
if (ret) {
115101
vfree(firmware);
116102
return ret;
@@ -122,8 +108,8 @@ static void clean_firmware_sysfs(struct intel_gvt *gvt)
122108
{
123109
struct pci_dev *pdev = to_pci_dev(gvt->gt->i915->drm.dev);
124110

125-
device_remove_bin_file(&pdev->dev, &firmware_attr);
126-
vfree(firmware_attr.private);
111+
device_remove_bin_file(&pdev->dev, &bin_attr_gvt_firmware);
112+
vfree(bin_attr_gvt_firmware.private);
127113
}
128114

129115
/**

drivers/thermal/intel/int340x_thermal/int3400_thermal.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,7 @@ struct odvp_attr {
7373
struct device_attribute attr;
7474
};
7575

76-
static ssize_t data_vault_read(struct file *file, struct kobject *kobj,
77-
struct bin_attribute *attr, char *buf, loff_t off, size_t count)
78-
{
79-
memcpy(buf, attr->private + off, count);
80-
return count;
81-
}
82-
83-
static BIN_ATTR_RO(data_vault, 0);
76+
static BIN_ATTR_SIMPLE_RO(data_vault);
8477

8578
static struct bin_attribute *data_attributes[] = {
8679
&bin_attr_data_vault,

init/initramfs.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,7 @@ extern unsigned long __initramfs_size;
575575
#include <linux/initrd.h>
576576
#include <linux/kexec.h>
577577

578-
static ssize_t raw_read(struct file *file, struct kobject *kobj,
579-
struct bin_attribute *attr, char *buf,
580-
loff_t pos, size_t count)
581-
{
582-
memcpy(buf, attr->private + pos, count);
583-
return count;
584-
}
585-
586-
static BIN_ATTR(initrd, 0440, raw_read, NULL, 0);
578+
static BIN_ATTR(initrd, 0440, sysfs_bin_attr_simple_read, NULL, 0);
587579

588580
void __init reserve_initrd_mem(void)
589581
{

kernel/module/sysfs.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,6 @@ struct module_notes_attrs {
146146
struct bin_attribute attrs[] __counted_by(notes);
147147
};
148148

149-
static ssize_t module_notes_read(struct file *filp, struct kobject *kobj,
150-
struct bin_attribute *bin_attr,
151-
char *buf, loff_t pos, size_t count)
152-
{
153-
/*
154-
* The caller checked the pos and count against our size.
155-
*/
156-
memcpy(buf, bin_attr->private + pos, count);
157-
return count;
158-
}
159-
160149
static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
161150
unsigned int i)
162151
{
@@ -205,7 +194,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
205194
nattr->attr.mode = 0444;
206195
nattr->size = info->sechdrs[i].sh_size;
207196
nattr->private = (void *)info->sechdrs[i].sh_addr;
208-
nattr->read = module_notes_read;
197+
nattr->read = sysfs_bin_attr_simple_read;
209198
++nattr;
210199
}
211200
++loaded;

0 commit comments

Comments
 (0)