hwmon: Add a new macro sensor_sysfs_attr
PATCH 1/1 hwmon: Add a new macro sensor_sysfs_attr
The attribute definiations like &sensor_dev_attr_xx_xx.dev_attr.attr are widely used in drivers. So add a new macro sensor_sysfs_attr t to make it easier to understand and use.
For example, user can use the sensor_sysfs_attr(xx_xx) instead of &sensor_dev_attr_xx_xx.dev_attr.attr
--- include/linux/hwmon-sysfs.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/hwmon-sysfs.h +4 -0
@@ -14,6 +14,10 @@ struct sensor_device_attribute{struct device_attribute dev_attr;int index; }; + +#define to_sensor_sysfs_attr (_name) \ + (&sensor_dev_attr_##_name.dev_attr.attr) +#define to_sensor_dev_attr (_dev_attr) \ container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
Signature · 1 line
2.34.1
Guenter Roeck
maintainerQuoted 17 lines · Ma Jun
The attribute definiations like &sensor_dev_attr_xx_xx.dev_attr.attr are widely used in drivers. So add a new macro
sensor_sysfs_attrt to make it easier to understand and use.For example, user can use the
sensor_sysfs_attr(xx_xx)instead of &sensor_dev_attr_xx_xx.dev_attr.attrSigned-off-by Ma Jun <[email protected]>--- include/linux/hwmon-sysfs.h | 4 ++++ 1 file changed, 4 insertions(+)include/linux/hwmon-sysfs.h +0
-0
include/linux/hwmon-sysfs.h struct sensor_device_attribute{ · line 23
Quoted 10 lines
include/linux/hwmon-sysfs.h +4
-0@@ -14,6 +14,10 @@ struct sensor_device_attribute{struct device_attribute dev_attr;int index; }; + +#define to_sensor_sysfs_attr (_name) \ + (&sensor_dev_attr_##_name.dev_attr.attr) +#define to_sensor_dev_attr (_dev_attr) \ container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
No. This would just invite people to submit patches converting existing code to use this new macro. Instead of providing macros to support deprecated APIs, convert drivers to use an API which is not deprecated. This would for the most part avoid the need for including hwmon-sysfs.h in the first place and at the same time reduce driver code size significantly.
Guenter
Hi Guenter,
Quoted 24 lines · Guenter Roeck
Quoted 23 lines · Ma Jun
The attribute definiations like &sensor_dev_attr_xx_xx.dev_attr.attr are widely used in drivers. So add a new macro
sensor_sysfs_attrt to make it easier to understand and use.For example, user can use the
sensor_sysfs_attr(xx_xx)instead of &sensor_dev_attr_xx_xx.dev_attr.attrSigned-off-by Ma Jun <[email protected]>--- include/linux/hwmon-sysfs.h | 4 ++++ 1 file changed, 4 insertions(+)include/linux/hwmon-sysfs.h +3
-0@@ -14,6 +14,10 @@ struct sensor_device_attribute{struct device_attribute dev_attr;int index; }; + +#define to_sensor_sysfs_attr (_name) \ + (&sensor_dev_attr_##_name.dev_attr.attr)
Quoted 8 lines
include/linux/hwmon-sysfs.h struct sensor_device_attribute{ · line 23
Quoted 4 lines
include/linux/hwmon-sysfs.h +1
-0+#define to_sensor_dev_attr (_dev_attr) \ container_of(_dev_attr, struct sensor_device_attribute, dev_attr)No. This would just invite people to submit patches converting existing code to use this new macro. Instead of providing macros to support deprecated APIs, convert drivers to use an API which is not deprecated. This would for the
Which API is not deprecated do you mean?
Regards,
Ma Jun
Quoted 7 lines
most part avoid the need for including
hwmon-sysfs.hin the first place and at the same time reduce driver code size significantly.Guenter
Guenter Roeck
maintainerQuoted 36 lines · Jun
Hi Guenter,
Quoted 24 lines · Guenter Roeck
Quoted 23 lines · Ma Jun
The attribute definiations like &sensor_dev_attr_xx_xx.dev_attr.attr are widely used in drivers. So add a new macro
sensor_sysfs_attrt to make it easier to understand and use.For example, user can use the
sensor_sysfs_attr(xx_xx)instead of &sensor_dev_attr_xx_xx.dev_attr.attrSigned-off-by Ma Jun <[email protected]>--- include/linux/hwmon-sysfs.h | 4 ++++ 1 file changed, 4 insertions(+)include/linux/hwmon-sysfs.h +3
-0@@ -14,6 +14,10 @@ struct sensor_device_attribute{struct device_attribute dev_attr;int index; }; + +#define to_sensor_sysfs_attr (_name) \ + (&sensor_dev_attr_##_name.dev_attr.attr)Quoted 8 lines
include/linux/hwmon-sysfs.h struct sensor_device_attribute{ · line 23
Quoted 4 lines
include/linux/hwmon-sysfs.h +1
-0+#define to_sensor_dev_attr (_dev_attr) \ container_of(_dev_attr, struct sensor_device_attribute, dev_attr)No. This would just invite people to submit patches converting existing code to use this new macro. Instead of providing macros to support deprecated APIs, convert drivers to use an API which is not deprecated. This would for the
Quoted 2 lines
Which API is not deprecated do you mean?
[devm_]hwmon_device_register_with_info(). I don't want to encourage the use of non-standard sysfs atributes either (and, no, I still don't accept the idea that "frequency" would be a hardware monitoring attribute).
Guenter