Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91a69029 authored by Zhang Rui's avatar Zhang Rui Committed by Greg Kroah-Hartman
Browse files

sysfs: add parameter "struct bin_attribute *" in .read/.write methods for sysfs binary attributes



Well, first of all, I don't want to change so many files either.

What I do:
Adding a new parameter "struct bin_attribute *" in the
.read/.write methods for the sysfs binary attributes.

In fact, only the four lines change in fs/sysfs/bin.c and
include/linux/sysfs.h do the real work.
But I have to update all the files that use binary attributes
to make them compatible with the new .read and .write methods.
I'm not sure if I missed any. :(

Why I do this:
For a sysfs attribute, we can get a pointer pointing to the
struct attribute in the .show/.store method,
while we can't do this for the binary attributes.
I don't know why this is different, but this does make it not
so handy to use the binary attributes as the regular ones.
So I think this patch is reasonable. :)

Who benefits from it:
The patch that exposes ACPI tables in sysfs
requires such an improvement.
All the table binary attributes share the same .read method.
Parameter "struct bin_attribute *" is used to get
the table signature and instance number which are used to
distinguish different ACPI table binary attributes.

Without this parameter, we need to offer different .read methods
for different ACPI table binary attributes.
This is impossible as there are various ACPI tables on different
platforms, and we don't know what they are until they are loaded.

Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 51225039
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ static CLASS_DEVICE_ATTR(loading, 0644,
			 firmware_loading_show, firmware_loading_store);

static ssize_t firmware_data_read(struct kobject *kobj,
				  struct bin_attribute *bin_attr,
				  char *buffer, loff_t offset, size_t count)
{
	struct class_device *class_dev = to_class_dev(kobj);
@@ -88,6 +89,7 @@ static ssize_t firmware_data_read(struct kobject *kobj,
	return count;
}
static ssize_t firmware_data_write(struct kobject *kobj,
				   struct bin_attribute *bin_attr,
				   char *buffer, loff_t offset, size_t count)
{
	struct class_device *class_dev = to_class_dev(kobj);
+2 −2
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ static ssize_t firmware_loading_store(struct device *dev,
static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);

static ssize_t
firmware_data_read(struct kobject *kobj,
firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
		   char *buffer, loff_t offset, size_t count)
{
	struct device *dev = to_dev(kobj);
@@ -240,7 +240,7 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
 *	the driver as a firmware image.
 **/
static ssize_t
firmware_data_write(struct kobject *kobj,
firmware_data_write(struct kobject *kobj, struct bin_attribute *bin_attr,
		    char *buffer, loff_t offset, size_t count)
{
	struct device *dev = to_dev(kobj);
+6 −4
Original line number Diff line number Diff line
@@ -149,8 +149,9 @@ static ssize_t smi_data_buf_size_store(struct device *dev,
	return count;
}

static ssize_t smi_data_read(struct kobject *kobj, char *buf, loff_t pos,
			     size_t count)
static ssize_t smi_data_read(struct kobject *kobj,
			     struct bin_attribute *bin_attr,
			     char *buf, loff_t pos, size_t count)
{
	size_t max_read;
	ssize_t ret;
@@ -170,8 +171,9 @@ static ssize_t smi_data_read(struct kobject *kobj, char *buf, loff_t pos,
	return ret;
}

static ssize_t smi_data_write(struct kobject *kobj, char *buf, loff_t pos,
			      size_t count)
static ssize_t smi_data_write(struct kobject *kobj,
			      struct bin_attribute *bin_attr,
			      char *buf, loff_t pos, size_t count)
{
	ssize_t ret;

+15 −10
Original line number Diff line number Diff line
@@ -543,8 +543,9 @@ static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
	return ret_count;
}

static ssize_t read_rbu_data(struct kobject *kobj, char *buffer,
	loff_t pos, size_t count)
static ssize_t read_rbu_data(struct kobject *kobj,
			     struct bin_attribute *bin_attr,
			     char *buffer, loff_t pos, size_t count)
{
	ssize_t ret_count = 0;

@@ -591,8 +592,9 @@ static void callbackfn_rbu(const struct firmware *fw, void *context)
	spin_unlock(&rbu_data.lock);
}

static ssize_t read_rbu_image_type(struct kobject *kobj, char *buffer,
	loff_t pos, size_t count)
static ssize_t read_rbu_image_type(struct kobject *kobj,
				   struct bin_attribute *bin_attr,
				   char *buffer, loff_t pos, size_t count)
{
	int size = 0;
	if (!pos)
@@ -600,8 +602,9 @@ static ssize_t read_rbu_image_type(struct kobject *kobj, char *buffer,
	return size;
}

static ssize_t write_rbu_image_type(struct kobject *kobj, char *buffer,
	loff_t pos, size_t count)
static ssize_t write_rbu_image_type(struct kobject *kobj,
				    struct bin_attribute *bin_attr,
				    char *buffer, loff_t pos, size_t count)
{
	int rc = count;
	int req_firm_rc = 0;
@@ -660,8 +663,9 @@ static ssize_t write_rbu_image_type(struct kobject *kobj, char *buffer,
	return rc;
}

static ssize_t read_rbu_packet_size(struct kobject *kobj, char *buffer,
	loff_t pos, size_t count)
static ssize_t read_rbu_packet_size(struct kobject *kobj,
				    struct bin_attribute *bin_attr,
				    char *buffer, loff_t pos, size_t count)
{
	int size = 0;
	if (!pos) {
@@ -672,8 +676,9 @@ static ssize_t read_rbu_packet_size(struct kobject *kobj, char *buffer,
	return size;
}

static ssize_t write_rbu_packet_size(struct kobject *kobj, char *buffer,
	loff_t pos, size_t count)
static ssize_t write_rbu_packet_size(struct kobject *kobj,
				     struct bin_attribute *bin_attr,
				     char *buffer, loff_t pos, size_t count)
{
	unsigned long temp;
	spin_lock(&rbu_data.lock);
+2 −1
Original line number Diff line number Diff line
@@ -110,7 +110,8 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice)
	mutex_unlock(&data->update_lock);
}

static ssize_t eeprom_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
static ssize_t eeprom_read(struct kobject *kobj, struct bin_attribute *bin_attr,
			   char *buf, loff_t off, size_t count)
{
	struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj));
	struct eeprom_data *data = i2c_get_clientdata(client);
Loading