Skip to contentSkip to conversation

hwmon-sysfs.h: add _RO and _RW versions of

PATCH New Jim Cromie 2 participants 3 messages Oct 8, 2006 – Oct 11, 2006

Subsystems (2)
lore
Share & tools
lore

Jim Cromie

author
#0 lore raw

PATCH 1/1 hwmon-sysfs.h: add _RO and _RW versions of

hi Jean,

1st attachment adds _RO and _RW versions to the following macros:
SENSOR_ATTR, SENSOR_DEVICE_ATTR,
SENSOR_ATTR_2, SENSOR_DEVICE_ATTR_2,

with these defined, the script (2nd attachment) will convert ~800 uses (in 17 files) to the correct _RO/_RW version, and remove the linewraps. The results compile cleanly (all modules in hwmon).

Is this something you'd consider applying ? If so, when ?
Theres obvious timing issues - since this patch touches many drivers,
which may have
work in-queue (yours or other hackers'). Its also why I sent the script
- the patch
it yields is 94KB, so the script is far more inspectable, and with the
script, you
can chose the optimal time(s) w/o synchronization hassles.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: diff.ro-rw.20061008.094436
Url: http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20061008/b684751b/attachment.pl
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ro-rw-change
Url: http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20061008/b684751b/attachment-0001.pl

#1 lore raw

PATCH 1/1 hwmon-sysfs.h: add _RO and _RW versions of

Hi Jim,

Quoted 7 lines

1st attachment adds _RO and _RW versions to the following macros:
SENSOR_ATTR, SENSOR_DEVICE_ATTR,
SENSOR_ATTR_2, SENSOR_DEVICE_ATTR_2,

with these defined, the script (2nd attachment) will convert ~800 uses (in 17 files) to the correct _RO/_RW version, and remove the linewraps. The results compile cleanly (all modules in hwmon).

What are you trying to achieve?

May you please post a sample patch as obtained by using the script above on one arbitrary driver? So that we can see what it looks like.

Quoted 1 line

Is this something you'd consider applying ? If so, when ?

It merely depends on what our purpose is. As for "when", remember that we have two high priority tasks for hwmon drivers now: individual alarm files, and i2c-isa removal. I would like the first one to be done for 2.6.20, and the second in 2.6.21 but individual drivers can (should) be converted to platform drivers before that. These will be large and intrusive patches and I am unlikely to take other large and intrudive patches until it's done.

Quoted 5 lines

Theres obvious timing issues - since this patch touches many drivers, which may have work in-queue (yours or other hackers'). Its also why I sent the script - the patch it yields is 94KB, so the script is far more inspectable, and with the script, you can chose the optimal time(s) w/o synchronization hassles.

Yes, sounds like a good idea, even though in this case your script is rather frightening. I can't get why you didn't write a real perl script? It would perform better and would certainly be somewhat more readable too.

Thanks,

Signature · 1 line
Jean Delvare
author
#2 lore raw

PATCH 1/1 hwmon-sysfs.h: add _RO and _RW versions of

In reply to Jim Cromie
Quoted 7 lines · Jean Delvare

Hi Jim,

Quoted 4 lines

1st attachment adds _RO and _RW versions to the following macros:
SENSOR_ATTR, SENSOR_DEVICE_ATTR,
SENSOR_ATTR_2, SENSOR_DEVICE_ATTR_2,

Quoted 8 lines
Quoted 4 lines

with these defined, the script (2nd attachment) will convert ~800 uses (in 17 files) to the correct _RO/_RW version, and remove the linewraps. The results compile cleanly (all modules in hwmon).

What are you trying to achieve?

cosmetics and abstraction.
- the 800 uses effectively have 2 modes; 0644 and 0444, but have multiple ways of saying it
- these permissions approach 'canonical' use, so if we hide them, exceptions become more distinct.
- lines are shorter, much less line-wrap fussing.

Quoted 4 lines

May you please post a sample patch as obtained by using the script above on one arbitrary driver? So that we can see what it looks like.

ok. Ive in-lined the patch to hwmon-sysfs.h, and the script's conversion of f71805f.c

Quoted 19 lines
Quoted 2 lines

Is this something you'd consider applying ? If so, when ?

It merely depends on what our purpose is. As for "when", remember that we have two high priority tasks for hwmon drivers now: individual alarm files, and i2c-isa removal. I would like the first one to be done for 2.6.20, and the second in 2.6.21 but individual drivers can (should) be converted to platform drivers before that. These will be large and intrusive patches and I am unlikely to take other large and intrudive patches until it's done.

Quoted 6 lines

Theres obvious timing issues - since this patch touches many drivers, which may have work in-queue (yours or other hackers'). Its also why I sent the script - the patch it yields is 94KB, so the script is far more inspectable, and with the script, you can chose the optimal time(s) w/o synchronization hassles.

Quoted 6 lines

Yes, sounds like a good idea, even though in this case your script is rather frightening. I can't get why you didn't write a real perl script? It would perform better and would certainly be somewhat more readable too.

its an assembly of 1-liners.
regexs always look like line-noise, its their nature. runtime on hwmon/*.c was <5 sec, hardly prohibitive for a 1-time script.

That said, Ive rewritten it as a pure perl script, attached. use it like so:
perl chg-ro drivers/hwmon/*.c

include/linux/hwmon-sysfs.h +28 -0
diff -ruNp -X dontdiff -X exclude-diffs 19rc1-0/include/linux/hwmon-sysfs.h ro-rw/include/linux/hwmon-sysfs.h
@@ -31,10 +31,24 @@ struct sensor_device_attribute{
 	{ .dev_attr = __ATTR(_name, _mode, _show, _store),	\
 	  .index = _index }
 
+#define SENSOR_ATTR_RO(_name, _show, _index)	\
+	SENSOR_ATTR(_name, S_IRUGO, _show, NULL, _index)
+
+#define SENSOR_ATTR_RW(_name, _show, _store, _index)	\
+	SENSOR_ATTR(_name, S_IRUGO | S_IWUSR, _show, _store, _index)
+
 #define SENSOR_DEVICE_ATTR(_name, _mode, _show, _store, _index)	\
 struct sensor_device_attribute sensor_dev_attr_##_name		\
 	= SENSOR_ATTR(_name, _mode, _show, _store, _index)
 
+#define SENSOR_DEVICE_ATTR_RO(_name, _show, _index)	\
+struct sensor_device_attribute sensor_dev_attr_##_name	\
+	= SENSOR_ATTR_RO(_name, _show, _index)
+
+#define SENSOR_DEVICE_ATTR_RW(_name, _show, _store, _index)	\
+struct sensor_device_attribute sensor_dev_attr_##_name		\
+	= SENSOR_ATTR_RW(_name, _show, _store, _index)
+
 struct sensor_device_attribute_2 {
 	struct device_attribute dev_attr;
 	u8 index;
@@ -48,8 +62,22 @@ struct sensor_device_attribute_2 {
 	  .index = _index,					\
 	  .nr = _nr }
 
+#define SENSOR_ATTR_2RO(_name, _show, _nr, _index)		\
+	SENSOR_ATTR_2(_name, S_IRUGO, _show, NULL, _nr, _index)
+
+#define SENSOR_ATTR_2RW(_name, _show, _store, _nr, _index)	\
+	SENSOR_ATTR_2(_name, S_IRUGO | S_IWUSR, _show, _store, _nr, _index)
+
 #define SENSOR_DEVICE_ATTR_2(_name,_mode,_show,_store,_nr,_index)	\
 struct sensor_device_attribute_2 sensor_dev_attr_##_name		\
 	= SENSOR_ATTR_2(_name, _mode, _show, _store, _nr, _index)
 
+#define SENSOR_DEVICE_ATTR_2RO(_name,_show,_nr,_index)		\
+struct sensor_device_attribute_2 sensor_dev_attr_##_name	\
+	= SENSOR_ATTR_2RO(_name, _show, _nr, _index)
+
+#define SENSOR_DEVICE_ATTR_2RW(_name,_show,_store,_nr,_index)	\
+struct sensor_device_attribute_2 sensor_dev_attr_##_name	\
+	= SENSOR_ATTR_2RW(_name, _show, _store, _nr, _index)
+
 #endif /* _LINUX_HWMON_SYSFS_H */
drivers/hwmon/f71805f.c +60 -85

151 lines not on this page · raw message

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: chg-ro
Url: http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20061010/3d42e697/attachment-0001.pl