All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Joshua Kinard <kumba@gentoo.org>,
	Alessandro Zummo <a.zummo@towertech.it>,
	rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org
Subject: [rtc-linux] Re: [PATCH 2/2] drivers/rtc/rtc-ds1685.c: don't try to micromanage sysfs output size
Date: Mon, 30 Nov 2015 20:06:27 +0100	[thread overview]
Message-ID: <20151130190627.GO22136@piout.net> (raw)
In-Reply-To: <1448373085-6353-2-git-send-email-linux@rasmusvillemoes.dk>

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

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Joshua Kinard <kumba@gentoo.org>,
	Alessandro Zummo <a.zummo@towertech.it>,
	rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] drivers/rtc/rtc-ds1685.c: don't try to micromanage sysfs output size
Date: Mon, 30 Nov 2015 20:06:27 +0100	[thread overview]
Message-ID: <20151130190627.GO22136@piout.net> (raw)
In-Reply-To: <1448373085-6353-2-git-send-email-linux@rasmusvillemoes.dk>

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

  reply	other threads:[~2015-11-30 19:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 13:51 [rtc-linux] [PATCH 1/2] drivers/rtc: use %ph for short hex dumps Rasmus Villemoes
2015-11-24 13:51 ` Rasmus Villemoes
2015-11-24 13:51 ` [rtc-linux] [PATCH 2/2] drivers/rtc/rtc-ds1685.c: don't try to micromanage sysfs output size Rasmus Villemoes
2015-11-24 13:51   ` Rasmus Villemoes
2015-11-30 19:06   ` Alexandre Belloni [this message]
2015-11-30 19:06     ` Alexandre Belloni
2015-11-30 19:06 ` [rtc-linux] Re: [PATCH 1/2] drivers/rtc: use %ph for short hex dumps Alexandre Belloni
2015-11-30 19:06   ` Alexandre Belloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151130190627.GO22136@piout.net \
    --to=alexandre.belloni@free-electrons.com \
    --cc=a.zummo@towertech.it \
    --cc=kumba@gentoo.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=rtc-linux@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.