Skip to contentSkip to conversation

refactor SENSOR-DEVICE-ATTR

PATCH New Jim Cromie 1 participant 1 message Aug 4, 2005 Hardware monitoring

lore
Share & tools
lore

Jim Cromie

author
#0 lore raw

PATCH 5/6 refactor SENSOR-DEVICE-ATTR

Quoted 6 lines · Jim Cromie

refactor SENSOR_DEVICE_ATTR into declaration = initialization-expression
__SENSOR_DEVICE_ATTR() expands to init-expr

this imitates __ATTR in include/linux/device.h,
but is needed cuz of new .index member ( otherwize __ATTR would suffice)

$ diffstat 05-pc87360-hwmon-sysfs-array-init.patch
 hwmon-sysfs.h |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

-------------- next part --------------

include/linux/hwmon-sysfs.h +14 -6
diff -ruNp -X exclude-diffs gc-4/include/linux/hwmon-sysfs.h gc-5/include/linux/hwmon-sysfs.h
@@ -27,12 +27,16 @@ struct sensor_device_attribute{
 #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),	\
+#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)
+
+
 struct sensor_device_attribute_2 {
 	struct device_attribute dev_attr;
 	u8 index;
@@ -41,11 +45,15 @@ struct sensor_device_attribute_2 {
 #define to_sensor_dev_attr_2(_dev_attr) \
 	container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
 
-#define SENSOR_DEVICE_ATTR_2(_name,_mode,_show,_store,_nr,_index)	\
-struct sensor_device_attribute_2 sensor_dev_attr_##_name = {	\
-	.dev_attr =	__ATTR(_name,_mode,_show,_store),	\
+#define __SENSOR_DEVICE_ATTR_2(_name,_mode,_show,_store,_nr,_index)	\
+{	.dev_attr =	__ATTR(_name,_mode,_show,_store),	\
 	.index =	_index,					\
 	.nr =		_nr,					\
 }
 
+#define SENSOR_DEVICE_ATTR_2(_name,_mode,_show,_store,_nr,_index)	\
+struct sensor_device_attribute_2 sensor_dev_attr_##_name 		\
+	= __SENSOR_DEVICE_ATTR_2(_name,_mode,_show,_store,_nr,_index)
+
+
 #endif /* _LINUX_HWMON_SYSFS_H */