All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] PATCH:
@ 2007-09-21 15:03 Hans de Goede
  2007-09-24 14:28 ` Jean Delvare
                   ` (19 more replies)
  0 siblings, 20 replies; 22+ messages in thread
From: Hans de Goede @ 2007-09-21 15:03 UTC (permalink / raw)
  To: lm-sensors

[-- Attachment #1: Type: text/plain, Size: 281 bytes --]

Hi All,

Here is a patch adding some text to the sysfs interface documentation on how
settings written to sysfs attributes should be handled, focussing mainly on
error handling. This version incorperates Jean's latest comments.

signed-off-by: j.w.r.degoede@hhs.nl

Regards,

Hans

[-- Attachment #2: documentation-hwmon-sysfs-interface-attr-write.patch --]
[-- Type: text/x-patch, Size: 3347 bytes --]

Here is a patch adding some text to the sysfs interface documentation on how
settings written to sysfs attributes should be handled, focussing mainly on
error handling. This version incorperates Jean's latest comments.

signed-off-by: j.w.r.degoede@hhs.nl
diff -ur linux-2.6.23-rc6.git4/Documentation.orig/hwmon/sysfs-interface linux-2.6.23-rc6.git4/Documentation/hwmon/sysfs-interface
--- linux-2.6.23-rc6.git4/Documentation.orig/hwmon/sysfs-interface	2007-09-21 15:33:10.000000000 +0200
+++ linux-2.6.23-rc6.git4/Documentation/hwmon/sysfs-interface	2007-09-21 16:55:09.000000000 +0200
@@ -67,6 +67,10 @@
 alarm (for example, whether a threshold must be met or must be exceeded
 to cause an alarm) is chip-dependent.
 
+When setting values of hwmon sysfs attributes, the string representation of
+the desired value must be written, note that strings which are not a number
+are interpreted as 0! For more on how written strings are interpreted see the
+"sysfs attribute writes interpretation" section at the end of this file.
 
 -------------------------------------------------------------------------
 
@@ -404,3 +408,57 @@
 		0: disable
 		1: enable
 		RW
+
+
+sysfs attribute writes interpretation
+-------------------------------------
+
+hwmon sysfs attributes always contain numbers, so the first thing to do is to
+convert the input to a number, there are 2 ways todo this depending whether
+the number can be negative or not:
+unsigned long u = simple_strtoul(buf, NULL, 10);
+long s = simple_strtol(buf, NULL, 10);
+
+With buf being the buffer with the user input being passed by the kernel.
+Notice that we do not use the second argument of strto[u]l, and thus cannot
+tell when 0 is returned, if this was really 0 or is caused by invalid input.
+This is done deliberately as checking this everywhere would add a lot of
+code to the kernel.
+
+Notice that it is important to always store the converted value in an
+unsigned long or long, so that no wrap around can happen before any further
+checking.
+
+After the input string is converted to an (unsigned) long, the value should be
+checked if its acceptable. Be careful with further conversions on the value
+before checking it for validity, as these conversions could still cause a wrap
+around before the check. For example do not multiply the result, and only
+add/subtract if it has been divided before the add/subtract.
+
+What to do if a value is found to be invalid, depends on the type of the
+sysfs attribute that is being set. If it is a continuous setting like a
+tempX_max or inX_max attribute, then the value should be clamped to its
+limits using SENSORS_LIMIT(value, min_limit, max_limit). If it is not
+continuous like for example a tempX_type, then when an invalid value is
+written, -EINVAL should be returned.
+
+Example1, temp1_max, register is a signed 8 bit value (-128 - 127 degrees):
+--- begin code ---
+long v = simple_strtol(buf, NULL, 10) / 1000;
+SENSORS_LIMIT(v, -128, 127);
+/* write v to register */
+--- end code ---
+
+Example2, fan divider setting, valid values 2, 4 and 8:
+--- begin code ---
+unsigned long v = simple_strtoul(buf, NULL, 10);
+
+switch (v) {
+       case 2: v = 1; break;
+       case 4: v = 2; break;
+       case 8: v = 3; break;
+       default:
+               return -EINVAL;
+}
+/* write v to register */
+--- end code ---

[-- Attachment #3: Type: text/plain, Size: 153 bytes --]

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 22+ messages in thread
* [lm-sensors] Patch:
@ 2006-06-28 12:35 Jean Delvare
  0 siblings, 0 replies; 22+ messages in thread
From: Jean Delvare @ 2006-06-28 12:35 UTC (permalink / raw)
  To: lm-sensors

Hi Hans,

> Documentation update for the new bank1_types module param added by
> hwmon-abituguru-override-bank1detect.patch
> 
> This patch also adds what we know about different revisions of the uGuru
> and a note that the abituguru driver unfortunatly doesnot work at the
> latest and greatest motherboards, which have what I think is revision 4
> of the uGuru.

Applied, thanks.

-- 
Jean Delvare


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2009-01-30 11:06 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-21 15:03 [lm-sensors] PATCH: Hans de Goede
2007-09-24 14:28 ` Jean Delvare
2007-10-07  8:19 ` Jean Delvare
2007-10-07 11:37 ` Hans de Goede
2007-10-07 18:24 ` Mark M. Hoffman
2007-10-07 18:28 ` Mark M. Hoffman
2007-10-07 20:41 ` Jean Delvare
2007-10-07 22:05 ` Jean Delvare
2007-10-31  8:42 ` Hans de Goede
2007-10-31 15:17 ` Jean Delvare
2007-11-01 23:00 ` Jean Delvare
2007-11-02  7:35 ` Hans de Goede
2007-11-02  9:44 ` Jean Delvare
2007-11-02 19:41 ` Hans de Goede
2007-11-03 16:29 ` Jean Delvare
2007-11-04 13:21 ` Hans de Goede
2007-12-17 15:56 ` Hans de Goede
2007-12-18 13:29 ` Jean Delvare
2008-06-30 14:53 ` Hans de Goede
2009-01-30 10:29 ` Hans de Goede
2009-01-30 11:06 ` Jean Delvare
  -- strict thread matches above, loose matches on Subject: below --
2006-06-28 12:35 [lm-sensors] Patch: Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.