Linux-Fsdevel Archive on lore.kernel.org help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com> To: hch@lst.de, viro@ZenIV.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, willy@infradead.org, kernel-team@fb.com Subject: [PATCH 4/6] sysctl: make proc_put_long() use scnprintf Date: Thu, 13 Aug 2020 17:04:09 -0400 [thread overview] Message-ID: <20200813210411.905010-5-josef@toxicpanda.com> (raw) In-Reply-To: <20200813210411.905010-1-josef@toxicpanda.com> Now that we're passing down a kernel buffer with enough space to account for an extra NULL terminator, go ahead and use scnprintf() to print out a long in proc_put_long(). count here includes NULL terminator slot in the buffer, so we will get the correct behavior we're looking for. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- kernel/sysctl.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 287862f91717..d8cc8737f58f 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -484,6 +484,7 @@ static int proc_get_long(char **buf, size_t *size, return 0; } +#undef TMPBUFLEN /** * proc_put_long - converts an integer to a decimal ASCII formatted string @@ -498,18 +499,12 @@ static int proc_get_long(char **buf, size_t *size, */ static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg) { - int len; - char tmp[TMPBUFLEN], *p = tmp; + size_t ret; - sprintf(p, "%s%lu", neg ? "-" : "", val); - len = strlen(tmp); - if (len > *size) - len = *size; - memcpy(*buf, tmp, len); - *size -= len; - *buf += len; + ret = scnprintf(*buf, *size, "%s%lu", neg ? "-" : "", val); + *size -= ret; + *buf += ret; } -#undef TMPBUFLEN static void proc_put_char(void **buf, size_t *size, char c) { -- 2.24.1
next prev parent reply other threads:[~2020-08-13 21:04 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-13 21:04 [PATCH 0/6] Some buffer management fixes for proc Josef Bacik 2020-08-13 21:04 ` [PATCH 1/6] proc: use vmalloc for our kernel buffer Josef Bacik 2020-09-01 15:14 ` Christoph Hellwig 2020-08-13 21:04 ` [PATCH 2/6] tree-wide: rename vmemdup_user to kvmemdup_user Josef Bacik 2020-09-01 15:14 ` Christoph Hellwig 2020-08-13 21:04 ` [PATCH 3/6] proc: allocate count + 1 for our read buffer Josef Bacik 2020-09-01 15:14 ` Christoph Hellwig 2020-08-13 21:04 ` Josef Bacik [this message] 2020-09-01 15:15 ` [PATCH 4/6] sysctl: make proc_put_long() use scnprintf Christoph Hellwig 2020-08-13 21:04 ` [PATCH 5/6] parport: rework procfs handlers to take advantage of the new buffer Josef Bacik 2020-09-01 15:15 ` Christoph Hellwig 2020-08-13 21:04 ` [PATCH 6/6] sunrpc: rework proc " Josef Bacik 2020-09-01 15:15 ` Christoph Hellwig
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=20200813210411.905010-5-josef@toxicpanda.com \ --to=josef@toxicpanda.com \ --cc=hch@lst.de \ --cc=kernel-team@fb.com \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=viro@ZenIV.linux.org.uk \ --cc=willy@infradead.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).