Commit 66bc1a17 authored by Lukas Wunner's avatar Lukas Wunner Committed by Greg Kroah-Hartman
Browse files

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: default avatarLukas Wunner <lukas@wunner.de>
Acked-by: default avatarZhi Wang <zhiwang@kernel.org>
Acked-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Acked-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/92ee0a0e83a5a3f3474845db6c8575297698933a.1712410202.git.lukas@wunner.de


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d48c0319
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -792,14 +792,6 @@ static int __init opal_sysfs_init(void)
	return 0;
}

static ssize_t export_attr_read(struct file *fp, struct kobject *kobj,
				struct bin_attribute *bin_attr, char *buf,
				loff_t off, size_t count)
{
	return memory_read_from_buffer(buf, count, &off, bin_attr->private,
				       bin_attr->size);
}

static int opal_add_one_export(struct kobject *parent, const char *export_name,
			       struct device_node *np, const char *prop_name)
{
@@ -826,7 +818,7 @@ static int opal_add_one_export(struct kobject *parent, const char *export_name,
	sysfs_bin_attr_init(attr);
	attr->attr.name = name;
	attr->attr.mode = 0400;
	attr->read = export_attr_read;
	attr->read = sysfs_bin_attr_simple_read;
	attr->private = __va(vals[0]);
	attr->size = vals[1];

+1 −8
Original line number Diff line number Diff line
@@ -29,14 +29,7 @@ BGRT_SHOW(type, image_type);
BGRT_SHOW(xoffset, image_offset_x);
BGRT_SHOW(yoffset, image_offset_y);

static ssize_t image_read(struct file *file, struct kobject *kobj,
	       struct bin_attribute *attr, char *buf, loff_t off, size_t count)
{
	memcpy(buf, attr->private + off, count);
	return count;
}

static BIN_ATTR_RO(image, 0);	/* size gets filled in later */
static BIN_ATTR_SIMPLE_RO(image);

static struct attribute *bgrt_attributes[] = {
	&bgrt_attr_version.attr,
+2 −10
Original line number Diff line number Diff line
@@ -746,16 +746,8 @@ static void __init dmi_scan_machine(void)
	pr_info("DMI not present or invalid.\n");
}

static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
			      struct bin_attribute *attr, char *buf,
			      loff_t pos, size_t count)
{
	memcpy(buf, attr->private + pos, count);
	return count;
}

static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0);
static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0);
static BIN_ATTR_SIMPLE_ADMIN_RO(smbios_entry_point);
static BIN_ATTR_SIMPLE_ADMIN_RO(DMI);

static int __init dmi_init(void)
{
+1 −9
Original line number Diff line number Diff line
@@ -40,15 +40,7 @@ static u8 *rci2_base;
static u32 rci2_table_len;
unsigned long rci2_table_phys __ro_after_init = EFI_INVALID_TABLE_ADDR;

static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
			      struct bin_attribute *attr, char *buf,
			      loff_t pos, size_t count)
{
	memcpy(buf, attr->private + pos, count);
	return count;
}

static BIN_ATTR(rci2, S_IRUSR, raw_table_read, NULL, 0);
static BIN_ATTR_SIMPLE_ADMIN_RO(rci2);

static u16 checksum(void)
{
+6 −20
Original line number Diff line number Diff line
@@ -50,21 +50,7 @@ struct gvt_firmware_header {

#define dev_to_drm_minor(d) dev_get_drvdata((d))

static ssize_t
gvt_firmware_read(struct file *filp, struct kobject *kobj,
	     struct bin_attribute *attr, char *buf,
	     loff_t offset, size_t count)
{
	memcpy(buf, attr->private + offset, count);
	return count;
}

static struct bin_attribute firmware_attr = {
	.attr = {.name = "gvt_firmware", .mode = (S_IRUSR)},
	.read = gvt_firmware_read,
	.write = NULL,
	.mmap = NULL,
};
static BIN_ATTR_SIMPLE_ADMIN_RO(gvt_firmware);

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

	firmware_attr.size = size;
	firmware_attr.private = firmware;
	bin_attr_gvt_firmware.size = size;
	bin_attr_gvt_firmware.private = firmware;

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

	device_remove_bin_file(&pdev->dev, &firmware_attr);
	vfree(firmware_attr.private);
	device_remove_bin_file(&pdev->dev, &bin_attr_gvt_firmware);
	vfree(bin_attr_gvt_firmware.private);
}

/**
Loading