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 6/6] sunrpc: rework proc handlers to take advantage of the new buffer
Date: Thu, 13 Aug 2020 17:04:11 -0400 [thread overview]
Message-ID: <20200813210411.905010-7-josef@toxicpanda.com> (raw)
In-Reply-To: <20200813210411.905010-1-josef@toxicpanda.com>
Now that we're allocating an extra slot for the NULL terminated string,
use scnprintf() and write directly into the buffer.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
net/sunrpc/sysctl.c | 10 ++--------
net/sunrpc/xprtrdma/svc_rdma.c | 16 ++--------------
2 files changed, 4 insertions(+), 22 deletions(-)
diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c
index 999eee1ed61c..31ed530d9846 100644
--- a/net/sunrpc/sysctl.c
+++ b/net/sunrpc/sysctl.c
@@ -117,14 +117,8 @@ proc_dodebug(struct ctl_table *table, int write, void *buffer, size_t *lenp,
if (strcmp(table->procname, "rpc_debug") == 0)
rpc_show_tasks(&init_net);
} else {
- len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
- if (len > left)
- len = left;
- memcpy(buffer, tmpbuf, len);
- if ((left -= len) > 0) {
- *((char *)buffer + len) = '\n';
- left--;
- }
+ len = scnprintf(buffer, *lenp, "0x%04x\n", *(unsigned int *) table->data);
+ left -= len;
}
done:
diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
index 526da5d4710b..9b3a113598af 100644
--- a/net/sunrpc/xprtrdma/svc_rdma.c
+++ b/net/sunrpc/xprtrdma/svc_rdma.c
@@ -90,20 +90,8 @@ static int read_reset_stat(struct ctl_table *table, int write,
if (write)
atomic_set(stat, 0);
else {
- char str_buf[32];
- int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
- if (len >= 32)
- return -EFAULT;
- len = strlen(str_buf);
- if (*ppos > len) {
- *lenp = 0;
- return 0;
- }
- len -= *ppos;
- if (len > *lenp)
- len = *lenp;
- if (len)
- memcpy(buffer, str_buf, len);
+ size_t len = scnprintf(buffer, *lenp, "%d\n",
+ atomic_read(stat));
*lenp = len;
*ppos += len;
}
--
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 ` [PATCH 4/6] sysctl: make proc_put_long() use scnprintf Josef Bacik
2020-09-01 15:15 ` 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 ` Josef Bacik [this message]
2020-09-01 15:15 ` [PATCH 6/6] sunrpc: rework proc " 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-7-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 \
--subject='Re: [PATCH 6/6] sunrpc: rework proc handlers to take advantage of the new buffer' \
/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
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).