refactor SENSORS_DEV_ATTR: was pc87360
PATCH 1/1 refactor SENSORS_DEV_ATTR: was pc87360
Quoted 7 lines · Jean Delvare
Hi Jim,
Quoted 2 lines · Jim Cromie
attached is a patch which:
Quoted 11 lines
Quoted 5 lines
1. adds an
__ATTR_Nmacro todevice.h,
which takes an extra_indexarg, and initializes device_attibute's new .index member.This seems to be duplicating the
SENSOR_DEVICE_ATTRmacro as defined ininclude/linux/hwmon-sysfs.h.
its almost the same - and was heavily inspired by it. The difference is that __ATTR_N is a smaller building block, it has only the RHS of the initialization, it does not have the variable declaration or the assignment/initialization itself.
So attached patch refactors SENSOR_DEV_ATTR into a declaration and an initialization expression, allowing latter to be used in array initializations.
-------------- next part --------------
include/linux/hwmon-sysfs.h renamed from linux-2.6.13-rc3-mm1/include/linux/hwmon-sysfs.h +7 -4
@@ -27,10 +27,13 @@#define to_sensor_dev_attr (_dev_attr) \ container_of(_dev_attr, struct sensor_device_attribute, dev_attr) -#define SENSOR_DEVICE_ATTR (_name,_mode,_show,_store,_index) \ -struct sensor_device_attribute sensor_dev_attr_##_name = { \ - .dev_attr = __ATTR(_name,_mode,_show,_store), \ - .index = _index, \ +#define __SENSOR_DEVICE_ATTR (_name,_mode,_show,_store,_index) \ + { .dev_attr = __ATTR(_name,_mode,_show,_store), \ + .index = _index, \ } +#define SENSOR_DEVICE_ATTR (_name,_mode,_show,_store,_index) \ +struct sensor_device_attribute sensor_dev_attr_##_name \ + = __SENSOR_DEVICE_ATTR(_name,_mode,_show,_store,_index) +#endif /* _LINUX_HWMON_SYSFS_H */