Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1280206

Re: [PATCH 2/2] drivers/rtc/rtc-ds1685.c: don't try to micromanage sysfs output size

From Alexandre Belloni <alexandre.belloni@free-electrons.com>
Newsgroups linux.kernel
Subject Re: [PATCH 2/2] drivers/rtc/rtc-ds1685.c: don't try to micromanage sysfs output size
Date 2015-11-30 20:10 +0100
Message-ID <qABZM-7C9-19@gated-at.bofh.it> (permalink)
References <qymiu-n6-23@gated-at.bofh.it> <qymiv-n6-31@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 24/11/2015 at 14:51:24 +0100, Rasmus Villemoes wrote :
> ...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>
> ---
>  drivers/rtc/rtc-ds1685.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
Applied, thanks.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] drivers/rtc: use %ph for short hex dumps Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-24 15:00 +0100
  [PATCH 2/2] drivers/rtc/rtc-ds1685.c: don't try to micromanage sysfs output size Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-24 15:00 +0100
    Re: [PATCH 2/2] drivers/rtc/rtc-ds1685.c: don't try to micromanage  sysfs output size Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2015-11-30 20:10 +0100
  Re: [PATCH 1/2] drivers/rtc: use %ph for short hex dumps Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2015-11-30 20:10 +0100

csiph-web