Skip to contentSkip to conversation

refactor SENSORS_DEV_ATTR: was pc87360

PATCH New Jim Cromie 1 participant 1 message Jul 28, 2005 Hardware monitoring

lore
Share & tools
lore

Jim Cromie

author
#0 lore raw

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_N macro to device.h,
which takes an extra _index arg, and initializes device_attibute's new .index member.

This seems to be duplicating the SENSOR_DEVICE_ATTR macro as defined in include/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
diff -ruN -X exclude-diffs ../linux-2.6.13-rc3-mm1/include/linux/hwmon-sysfs.h linux/include/linux/hwmon-sysfs.h
@@ -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 */