rtc: ds1685: don't try to micromanage sysfs output size
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Tue, 24 Nov 2015 13:51:24 +0000 (14:51 +0100)
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>
Mon, 11 Jan 2016 19:19:58 +0000 (20:19 +0100)
commit9c25a106c0dfc1656a147663c353e3805e6165da
treedc35a0f9e60d1ffe19cb9f40756036124ebe4ae1
parentff67abd236ca7b65ea632f476f0f0cfc83aea711
rtc: ds1685: don't try to micromanage sysfs output size

...and don't do it wrong.

"not ok or N/A" has length 13. Add the trailing newline, and the
snprintf return value will be 14. However, we lied to snprintf and
told it that only 13 bytes were available. Hence snprintf has only
written "not ok or N/" and a trailing '\0' to the buffer. Next we
continue lying, this time to the upper sysfs layer, claiming that we
wrote 14 meaningful bytes to the buffer. That'll make the upper layer
copy "not ok or N/" plus two nul bytes to user space (one nul byte
from snprintf, the other since sysfs takes care to clear the buffer
before giving it to the ->show method).

In the other cases, the claimed buffer size is closer to sufficient,
but we'll still get a nul byte instead of a newline written to user
space.  There's absolutely no reason to try to predict the output
size, and there's plenty of room in the buffer, so just use sprintf.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
drivers/rtc/rtc-ds1685.c