Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sysfs.txt: update show method notes about sprintf/snprintf/scnprintf usage

Changed the documentation to allow sprintf() when the buffer
provided by sysfs cannot be overflowed. Explicitly say
snprintf() must never be used in a show function to format
data to be returned to user space.

Change based on a discussion about the patch
st: convert DRIVER_ATTR macros to DRIVER_ATTR_RO

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Shane Seymour <shane.seymour@hp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Seymour, Shane M and committed by
Greg Kroah-Hartman
223e8f01 64526370

+4 -1
+4 -1
Documentation/filesystems/sysfs.txt
··· 212 212 - show() methods should return the number of bytes printed into the 213 213 buffer. This is the return value of scnprintf(). 214 214 215 - - show() should always use scnprintf(). 215 + - show() must not use snprintf() when formatting the value to be 216 + returned to user space. If you can guarantee that an overflow 217 + will never happen you can use sprintf() otherwise you must use 218 + scnprintf(). 216 219 217 220 - store() should return the number of bytes used from the buffer. If the 218 221 entire buffer has been used, just return the count argument.