Skip to content

Commit

Permalink
sysfs: add parameter "struct bin_attribute *" in .read/.write methods…
Browse files Browse the repository at this point in the history
… 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: Zhang Rui <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
zhang-rui authored and gregkh committed Jul 11, 2007
1 parent 5122503 commit 91a6902
Show file tree
Hide file tree
Showing 27 changed files with 185 additions and 106 deletions.
2 changes: 2 additions & 0 deletions Documentation/firmware_class/firmware_sample_firmware_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions drivers/base/firmware_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions drivers/firmware/dcdbas.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
25 changes: 15 additions & 10 deletions drivers/firmware/dell_rbu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -591,17 +592,19 @@ 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)
size = sprintf(buffer, "%s\n", image_type);
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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion drivers/i2c/chips/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions drivers/i2c/chips/max6875.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
mutex_unlock(&data->update_lock);
}

static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off,
size_t count)
static ssize_t max6875_read(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct i2c_client *client = kobj_to_i2c_client(kobj);
struct max6875_data *data = i2c_get_clientdata(client);
Expand Down
6 changes: 4 additions & 2 deletions drivers/pci/hotplug/acpiphp_ibm.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status);
static void ibm_handle_events(acpi_handle handle, u32 event, void *context);
static int ibm_get_table_from_acpi(char **bufp);
static ssize_t ibm_read_apci_table(struct kobject *kobj,
char *buffer, loff_t pos, size_t size);
struct bin_attribute *bin_attr,
char *buffer, loff_t pos, size_t size);
static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
u32 lvl, void *context, void **rv);
static int __init ibm_acpiphp_init(void);
Expand Down Expand Up @@ -357,7 +358,8 @@ static int ibm_get_table_from_acpi(char **bufp)
* our solution is to only allow reading the table in all at once
**/
static ssize_t ibm_read_apci_table(struct kobject *kobj,
char *buffer, loff_t pos, size_t size)
struct bin_attribute *bin_attr,
char *buffer, loff_t pos, size_t size)
{
int bytes_read = -EINVAL;
char *table = NULL;
Expand Down
18 changes: 12 additions & 6 deletions drivers/pci/pci-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ struct device_attribute pci_dev_attrs[] = {
};

static ssize_t
pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
pci_read_config(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
unsigned int size = 64;
Expand Down Expand Up @@ -285,7 +286,8 @@ pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
}

static ssize_t
pci_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
pci_write_config(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
unsigned int size = count;
Expand Down Expand Up @@ -352,7 +354,8 @@ pci_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
* callback routine (pci_legacy_read).
*/
ssize_t
pci_read_legacy_io(struct kobject *kobj, char *buf, loff_t off, size_t count)
pci_read_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct pci_bus *bus = to_pci_bus(container_of(kobj,
struct class_device,
Expand All @@ -376,7 +379,8 @@ pci_read_legacy_io(struct kobject *kobj, char *buf, loff_t off, size_t count)
* callback routine (pci_legacy_write).
*/
ssize_t
pci_write_legacy_io(struct kobject *kobj, char *buf, loff_t off, size_t count)
pci_write_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct pci_bus *bus = to_pci_bus(container_of(kobj,
struct class_device,
Expand Down Expand Up @@ -528,7 +532,8 @@ static inline void pci_remove_resource_files(struct pci_dev *dev) { return; }
* writing anything except 0 enables it
*/
static ssize_t
pci_write_rom(struct kobject *kobj, char *buf, loff_t off, size_t count)
pci_write_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));

Expand All @@ -551,7 +556,8 @@ pci_write_rom(struct kobject *kobj, char *buf, loff_t off, size_t count)
* device corresponding to @kobj.
*/
static ssize_t
pci_read_rom(struct kobject *kobj, char *buf, loff_t off, size_t count)
pci_read_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
void __iomem *rom;
Expand Down
8 changes: 6 additions & 2 deletions drivers/pcmcia/socket_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off
return (ret);
}

static ssize_t pccard_show_cis(struct kobject *kobj, char *buf, loff_t off, size_t count)
static ssize_t pccard_show_cis(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
unsigned int size = 0x200;

Expand Down Expand Up @@ -311,7 +313,9 @@ static ssize_t pccard_show_cis(struct kobject *kobj, char *buf, loff_t off, size
return (count);
}

static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, size_t count)
static ssize_t pccard_store_cis(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj));
cisdump_t *cis;
Expand Down
6 changes: 4 additions & 2 deletions drivers/rapidio/rio-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ struct device_attribute rio_dev_attrs[] = {
};

static ssize_t
rio_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
rio_read_config(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct rio_dev *dev =
to_rio_dev(container_of(kobj, struct device, kobj));
Expand Down Expand Up @@ -137,7 +138,8 @@ rio_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
}

static ssize_t
rio_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
rio_write_config(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct rio_dev *dev =
to_rio_dev(container_of(kobj, struct device, kobj));
Expand Down
10 changes: 6 additions & 4 deletions drivers/rtc/rtc-ds1553.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ static const struct rtc_class_ops ds1553_rtc_ops = {
.ioctl = ds1553_rtc_ioctl,
};

static ssize_t ds1553_nvram_read(struct kobject *kobj, char *buf,
loff_t pos, size_t size)
static ssize_t ds1553_nvram_read(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
struct platform_device *pdev =
to_platform_device(container_of(kobj, struct device, kobj));
Expand All @@ -272,8 +273,9 @@ static ssize_t ds1553_nvram_read(struct kobject *kobj, char *buf,
return count;
}

static ssize_t ds1553_nvram_write(struct kobject *kobj, char *buf,
loff_t pos, size_t size)
static ssize_t ds1553_nvram_write(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
struct platform_device *pdev =
to_platform_device(container_of(kobj, struct device, kobj));
Expand Down
10 changes: 6 additions & 4 deletions drivers/rtc/rtc-ds1742.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ static const struct rtc_class_ops ds1742_rtc_ops = {
.set_time = ds1742_rtc_set_time,
};

static ssize_t ds1742_nvram_read(struct kobject *kobj, char *buf,
loff_t pos, size_t size)
static ssize_t ds1742_nvram_read(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
struct platform_device *pdev =
to_platform_device(container_of(kobj, struct device, kobj));
Expand All @@ -141,8 +142,9 @@ static ssize_t ds1742_nvram_read(struct kobject *kobj, char *buf,
return count;
}

static ssize_t ds1742_nvram_write(struct kobject *kobj, char *buf,
loff_t pos, size_t size)
static ssize_t ds1742_nvram_write(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
struct platform_device *pdev =
to_platform_device(container_of(kobj, struct device, kobj));
Expand Down
10 changes: 6 additions & 4 deletions drivers/s390/cio/chp.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ static int s390_vary_chpid(struct chp_id chpid, int on)
/*
* Channel measurement related functions
*/
static ssize_t chp_measurement_chars_read(struct kobject *kobj, char *buf,
loff_t off, size_t count)
static ssize_t chp_measurement_chars_read(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct channel_path *chp;
unsigned int size;
Expand Down Expand Up @@ -192,8 +193,9 @@ static void chp_measurement_copy_block(struct cmg_entry *buf,
} while (reference_buf.values[0] != buf->values[0]);
}

static ssize_t chp_measurement_read(struct kobject *kobj, char *buf,
loff_t off, size_t count)
static ssize_t chp_measurement_read(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct channel_path *chp;
struct channel_subsystem *css;
Expand Down
15 changes: 9 additions & 6 deletions drivers/scsi/arcmsr/arcmsr_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@
struct class_device_attribute *arcmsr_host_attrs[];

static ssize_t
arcmsr_sysfs_iop_message_read(struct kobject *kobj, char *buf, loff_t off,
size_t count)
arcmsr_sysfs_iop_message_read(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct class_device *cdev = container_of(kobj,struct class_device,kobj);
struct Scsi_Host *host = class_to_shost(cdev);
Expand Down Expand Up @@ -105,8 +106,9 @@ arcmsr_sysfs_iop_message_read(struct kobject *kobj, char *buf, loff_t off,
}

static ssize_t
arcmsr_sysfs_iop_message_write(struct kobject *kobj, char *buf, loff_t off,
size_t count)
arcmsr_sysfs_iop_message_write(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct class_device *cdev = container_of(kobj,struct class_device,kobj);
struct Scsi_Host *host = class_to_shost(cdev);
Expand Down Expand Up @@ -152,8 +154,9 @@ arcmsr_sysfs_iop_message_write(struct kobject *kobj, char *buf, loff_t off,
}

static ssize_t
arcmsr_sysfs_iop_message_clear(struct kobject *kobj, char *buf, loff_t off,
size_t count)
arcmsr_sysfs_iop_message_clear(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct class_device *cdev = container_of(kobj,struct class_device,kobj);
struct Scsi_Host *host = class_to_shost(cdev);
Expand Down
Loading

0 comments on commit 91a6902

Please sign in to comment.