eeprom: ee1004: Let device core handle attribute eeprom
Subsystems (2)
cover eeprom: ee1004: Let device core handle attribute eeprom
Instead of creating/removing the attribute ourselves, just declare the attribute and let the device core handle it. This allows to simplify the code.
Heiner Kallweit (2):
sysfs: Add helper BIN_ATTRIBUTE_GROUPS
eeprom: ee1004: Let device core handle attribute eeprom
drivers/misc/eeprom/ee1004.c | 26 +++++++++----------------- include/linux/sysfs.h | 6 ++++++ 2 files changed, 15 insertions(+), 17 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 sysfs: Add helper BIN_ATTRIBUTE_GROUPS
New helper BIN_ATTRIBUTE_GROUPS() does the same as ATTRIBUTE_GROUPS(), just for binary attributes.
--- include/linux/sysfs.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/sysfs.h +6 -0
@@ -162,6 +162,12 @@ static const struct attribute_group _name##_group = { \ }; \ __ATTRIBUTE_GROUPS(_name) +#define BIN_ATTRIBUTE_GROUPS (_name) \ +static const struct attribute_group _name##_group = { \ + .bin_attrs = _name##_attrs, \ +}; \ +__ATTRIBUTE_GROUPS(_name) +struct file ;struct vm_area_struct ;struct address_space ;
Signature · 1 line
2.31.1
Greg Kroah-Hartman
maintainerRe: [PATCH 1/2] sysfs: Add helper BIN_ATTRIBUTE_GROUPS
Quoted 13 lines · Heiner Kallweit
New helper
BIN_ATTRIBUTE_GROUPS()does the same asATTRIBUTE_GROUPS(), just for binary attributes.Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/sysfs.h | 6 ++++++ 1 file changed, 6 insertions(+)include/linux/sysfs.h +0
-0
include/linux/sysfs.h static const struct attribute_group _name##_group = { \ · line 169
Quoted 8 lines
include/linux/sysfs.h +5
-0@@ -162,6 +162,12 @@ static const struct attribute_group _name##_group = { \ }; \ __ATTRIBUTE_GROUPS(_name) +#define BIN_ATTRIBUTE_GROUPS (_name) \ +static const struct attribute_group _name##_group = { \ + .bin_attrs = _name##_attrs, \ +}; \ +__ATTRIBUTE_GROUPS(_name)
Is this really needed by more than just 1 driver?
How about just "open code" this for now, binary sysfs files are rare.
thanks,
greg k-h
Re: [PATCH 1/2] sysfs: Add helper BIN_ATTRIBUTE_GROUPS
Quoted 17 lines · Greg Kroah-Hartman
Quoted 16 lines · Heiner Kallweit
New helper
BIN_ATTRIBUTE_GROUPS()does the same asATTRIBUTE_GROUPS(), just for binary attributes.Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/sysfs.h | 6 ++++++ 1 file changed, 6 insertions(+)include/linux/sysfs.h +0
-0@@ -162,6 +162,12 @@ static const struct attribute_group _name##_group = { \ }; \__ATTRIBUTE_GROUPS (_name)
Quoted 8 lines
include/linux/sysfs.h static const struct attribute_group _name##_group = { \ · line 169
Quoted 5 lines
include/linux/sysfs.h +5
-0+#define BIN_ATTRIBUTE_GROUPS (_name) \ +static const struct attribute_group _name##_group = { \ + .bin_attrs = _name##_attrs, \ +}; \ +__ATTRIBUTE_GROUPS(_name)Is this really needed by more than just 1 driver?
Few more use case I saw:devcd_dev_groups in drivers/base/devcoredump.cw1_f3a_group in drivers/w1/slaves/w1_ds2413.cw1_slave_default_groups in drivers/w1/w1.c
Quoted 6 lines
How about just "open code" this for now, binary sysfs files are rare.
thanks,
greg k-h
Heiner
Re: [PATCH 1/2] sysfs: Add helper BIN_ATTRIBUTE_GROUPS
Quoted 26 lines · Heiner Kallweit
Quoted 17 lines · Greg Kroah-Hartman
Quoted 16 lines · Heiner Kallweit
New helper
BIN_ATTRIBUTE_GROUPS()does the same asATTRIBUTE_GROUPS(), just for binary attributes.Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/sysfs.h | 6 ++++++ 1 file changed, 6 insertions(+)include/linux/sysfs.h +0
-0@@ -162,6 +162,12 @@ static const struct attribute_group _name##_group = { \ }; \__ATTRIBUTE_GROUPS (_name)Quoted 8 lines
include/linux/sysfs.h static const struct attribute_group _name##_group = { \ · line 169
Quoted 5 lines
include/linux/sysfs.h +5
-0+#define BIN_ATTRIBUTE_GROUPS (_name) \ +static const struct attribute_group _name##_group = { \ + .bin_attrs = _name##_attrs, \ +}; \ +__ATTRIBUTE_GROUPS(_name)Is this really needed by more than just 1 driver?
Quoted 4 lines
Few more use case I saw:
devcd_dev_groupsindrivers/base/devcoredump.cw1_f3a_groupindrivers/w1/slaves/w1_ds2413.cw1_slave_default_groupsindrivers/w1/w1.c
Ok, might as well, can't hurt to add this :)
Greg Kroah-Hartman
maintainerRe: [PATCH 1/2] sysfs: Add helper BIN_ATTRIBUTE_GROUPS
Quoted 27 lines · Greg Kroah-Hartman
Quoted 26 lines · Heiner Kallweit
Quoted 25 lines · Greg Kroah-Hartman
Quoted 13 lines · Heiner Kallweit
New helper
BIN_ATTRIBUTE_GROUPS()does the same asATTRIBUTE_GROUPS(), just for binary attributes.Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/sysfs.h | 6 ++++++ 1 file changed, 6 insertions(+)include/linux/sysfs.h +0
-0include/linux/sysfs.h static const struct attribute_group _name##_group = { \ · line 169
Quoted 8 lines
include/linux/sysfs.h +5
-0@@ -162,6 +162,12 @@ static const struct attribute_group _name##_group = { \ }; \ __ATTRIBUTE_GROUPS(_name) +#define BIN_ATTRIBUTE_GROUPS (_name) \ +static const struct attribute_group _name##_group = { \ + .bin_attrs = _name##_attrs, \ +}; \ +__ATTRIBUTE_GROUPS(_name)Is this really needed by more than just 1 driver?
Quoted 8 lines
Quoted 4 lines
Few more use case I saw:
devcd_dev_groupsindrivers/base/devcoredump.cw1_f3a_groupindrivers/w1/slaves/w1_ds2413.cw1_slave_default_groupsindrivers/w1/w1.cOk, might as well, can't hurt to add this :)
Reviewed-by Greg Kroah-Hartman <[email protected]>
Oh wait, I'm the maintainer of the other file that uses this, I'll take both of these then :)
thanks,
greg k-h
Re: [PATCH 1/2] sysfs: Add helper BIN_ATTRIBUTE_GROUPS
Quoted 33 lines · Greg Kroah-Hartman
Quoted 32 lines · Greg Kroah-Hartman
Quoted 30 lines · Heiner Kallweit
Quoted 17 lines · Greg Kroah-Hartman
Quoted 16 lines · Heiner Kallweit
New helper
BIN_ATTRIBUTE_GROUPS()does the same asATTRIBUTE_GROUPS(), just for binary attributes.Signed-off-by Heiner Kallweit <[email protected]>--- include/linux/sysfs.h | 6 ++++++ 1 file changed, 6 insertions(+)include/linux/sysfs.h +0
-0@@ -162,6 +162,12 @@ static const struct attribute_group _name##_group = { \ }; \__ATTRIBUTE_GROUPS (_name)Quoted 8 lines
include/linux/sysfs.h static const struct attribute_group _name##_group = { \ · line 169
Quoted 5 lines
include/linux/sysfs.h +5
-0+#define BIN_ATTRIBUTE_GROUPS (_name) \ +static const struct attribute_group _name##_group = { \ + .bin_attrs = _name##_attrs, \ +}; \ +__ATTRIBUTE_GROUPS(_name)Is this really needed by more than just 1 driver?
Few more use case I saw:
devcd_dev_groupsindrivers/base/devcoredump.cw1_f3a_groupindrivers/w1/slaves/w1_ds2413.cw1_slave_default_groupsindrivers/w1/w1.c
Quoted 7 lines
Quoted 3 lines
Ok, might as well, can't hurt to add this :)
Reviewed-by Greg Kroah-Hartman <[email protected]>Oh wait, I'm the maintainer of the other file that uses this, I'll take both of these then :)
Even better, thanks!
Quoted 4 lines
thanks,
greg k-h
Heiner
PATCH 2/2 eeprom: ee1004: Let device core handle attribute eeprom
In reply to Heiner KallweitInstead of creating/removing the attribute ourselves, just declare the attribute and let the device core handle it. This allows to simplify the code.
--- drivers/misc/eeprom/ee1004.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
drivers/misc/eeprom/ee1004.c +9 -17
@@ -89,7 +89,7 @@ static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,return status; } -static ssize_t ee1004_read (struct file *filp,struct kobject *kobj, +static ssize_t eeprom_read (struct file *filp,struct kobject *kobj,struct bin_attribute *bin_attr,char *buf,loff_t off,size_t count) {
@@ -160,15 +160,15 @@ static ssize_t ee1004_read(struct file *filp, struct kobject *kobj,return requested; } -static const struct bin_attribute eeprom_attr = { - .attr = { - .name ="eeprom" , - .mode =0444 , - }, - .size =EE1004_EEPROM_SIZE , - .read = ee1004_read, +static BIN_ATTR_RO(eeprom, EE1004_EEPROM_SIZE); + +static struct bin_attribute *ee1004_attrs[] = { + &bin_attr_eeprom, +NULL }; +BIN_ATTRIBUTE_GROUPS (ee1004); +static int ee1004_probe (struct i2c_client *client,const struct i2c_device_id *id) {
@@ -222,11 +222,6 @@ static int ee1004_probe(struct i2c_client *client, ee1004_current_page);mutex_unlock (&ee1004_bus_lock); -/* Create the sysfs eeprom file */ - err =sysfs_create_bin_file (&client->dev.kobj, &eeprom_attr); -if (err) - goto err_clients_lock; -dev_info (&client->dev,"%u byte EE1004-compliant SPD EEPROM, read-only\n" ,EE1004_EEPROM_SIZE );
@@ -237,8 +232,6 @@ static int ee1004_probe(struct i2c_client *client,return 0 ; - err_clients_lock: -mutex_lock (&ee1004_bus_lock); err_clients:if (--ee1004_dev_count ==0 ) {for (cnr--; cnr >=0 ; cnr--) {
@@ -255,8 +248,6 @@ static int ee1004_remove(struct i2c_client *client) {int i; -sysfs_remove_bin_file (&client->dev.kobj, &eeprom_attr); -/* Remove page select clients if this is the last device */ mutex_lock (&ee1004_bus_lock);if (--ee1004_dev_count ==0 ) {
@@ -275,6 +266,7 @@ static int ee1004_remove(struct i2c_client *client)static struct i2c_driver ee1004_driver = { .driver = { .name ="ee1004" , + .dev_groups = ee1004_groups, }, .probe = ee1004_probe, .remove = ee1004_remove,
Signature · 1 line
2.31.1
PATCH v2 1/1 eeprom: ee1004: Let device core handle attribute eeprom
In reply to Heiner KallweitInstead of creating/removing the attribute ourselves, just declare the attribute and let the device core handle it. This allows to simplify the code.
---
v2:
- open-code the proposed BIN_ATTRIBUTES_GROUPS macro I leave it to you which version you prefer.
--- drivers/misc/eeprom/ee1004.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/misc/eeprom/ee1004.c +13 -17
@@ -89,7 +89,7 @@ static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,return status; } -static ssize_t ee1004_read (struct file *filp,struct kobject *kobj, +static ssize_t eeprom_read (struct file *filp,struct kobject *kobj,struct bin_attribute *bin_attr,char *buf,loff_t off,size_t count) {
@@ -160,15 +160,19 @@ static ssize_t ee1004_read(struct file *filp, struct kobject *kobj,return requested; } -static const struct bin_attribute eeprom_attr = { - .attr = { - .name ="eeprom" , - .mode =0444 , - }, - .size =EE1004_EEPROM_SIZE , - .read = ee1004_read, +static BIN_ATTR_RO(eeprom, EE1004_EEPROM_SIZE); + +static struct bin_attribute *ee1004_attrs[] = { + &bin_attr_eeprom, +NULL +}; + +static const struct attribute_group ee1004_group = { + .bin_attrs = ee1004_attrs, }; +__ATTRIBUTE_GROUPS (ee1004); +static int ee1004_probe (struct i2c_client *client,const struct i2c_device_id *id) {
@@ -222,11 +226,6 @@ static int ee1004_probe(struct i2c_client *client, ee1004_current_page);mutex_unlock (&ee1004_bus_lock); -/* Create the sysfs eeprom file */ - err =sysfs_create_bin_file (&client->dev.kobj, &eeprom_attr); -if (err) - goto err_clients_lock; -dev_info (&client->dev,"%u byte EE1004-compliant SPD EEPROM, read-only\n" ,EE1004_EEPROM_SIZE );
@@ -237,8 +236,6 @@ static int ee1004_probe(struct i2c_client *client,return 0 ; - err_clients_lock: -mutex_lock (&ee1004_bus_lock); err_clients:if (--ee1004_dev_count ==0 ) {for (cnr--; cnr >=0 ; cnr--) {
@@ -255,8 +252,6 @@ static int ee1004_remove(struct i2c_client *client) {int i; -sysfs_remove_bin_file (&client->dev.kobj, &eeprom_attr); -/* Remove page select clients if this is the last device */ mutex_lock (&ee1004_bus_lock);if (--ee1004_dev_count ==0 ) {
@@ -275,6 +270,7 @@ static int ee1004_remove(struct i2c_client *client)static struct i2c_driver ee1004_driver = { .driver = { .name ="ee1004" , + .dev_groups = ee1004_groups, }, .probe = ee1004_probe, .remove = ee1004_remove,
Signature · 1 line
2.31.1
Greg added his Reviewed-by to v1, so you may disregard v2.
Quoted 92 lines · Heiner Kallweit
Instead of creating/removing the attribute ourselves, just declare the attribute and let the device core handle it. This allows to simplify the code.
Signed-off-by Heiner Kallweit <[email protected]>---
v2:
- open-code the proposedBIN_ATTRIBUTES_GROUPSmacro I leave it to you which version you prefer.--- drivers/misc/eeprom/ee1004.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)drivers/misc/eeprom/ee1004.c +13
-17@@ -89,7 +89,7 @@ static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,return status; } -static ssize_t ee1004_read (struct file *filp,struct kobject *kobj, +static ssize_t eeprom_read (struct file *filp,struct kobject *kobj,struct bin_attribute *bin_attr,char *buf,loff_t off,size_t count) {@@ -160,15 +160,19 @@ static ssize_t ee1004_read(struct file *filp, struct kobject *kobj,return requested; } -static const struct bin_attribute eeprom_attr = { - .attr = { - .name ="eeprom" , - .mode =0444 , - }, - .size =EE1004_EEPROM_SIZE , - .read = ee1004_read, +static BIN_ATTR_RO(eeprom, EE1004_EEPROM_SIZE); + +static struct bin_attribute *ee1004_attrs[] = { + &bin_attr_eeprom, +NULL +}; + +static const struct attribute_group ee1004_group = { + .bin_attrs = ee1004_attrs, }; +__ATTRIBUTE_GROUPS (ee1004); +static int ee1004_probe (struct i2c_client *client,const struct i2c_device_id *id) {@@ -222,11 +226,6 @@ static int ee1004_probe(struct i2c_client *client, ee1004_current_page);mutex_unlock (&ee1004_bus_lock); -/* Create the sysfs eeprom file */ - err =sysfs_create_bin_file (&client->dev.kobj, &eeprom_attr); -if (err) - goto err_clients_lock; -dev_info (&client->dev,"%u byte EE1004-compliant SPD EEPROM, read-only\n" ,EE1004_EEPROM_SIZE );@@ -237,8 +236,6 @@ static int ee1004_probe(struct i2c_client *client,return 0 ; - err_clients_lock: -mutex_lock (&ee1004_bus_lock); err_clients:if (--ee1004_dev_count ==0 ) {for (cnr--; cnr >=0 ; cnr--) {@@ -255,8 +252,6 @@ static int ee1004_remove(struct i2c_client *client) {int i; -sysfs_remove_bin_file (&client->dev.kobj, &eeprom_attr); -/* Remove page select clients if this is the last device */ mutex_lock (&ee1004_bus_lock);if (--ee1004_dev_count ==0 ) {@@ -275,6 +270,7 @@ static int ee1004_remove(struct i2c_client *client)static struct i2c_driver ee1004_driver = { .driver = { .name ="ee1004" , + .dev_groups = ee1004_groups, }, .probe = ee1004_probe, .remove = ee1004_remove,