* [PATCH] pstore/ram: Avoid needless alloc during header write
@ 2019-02-12 21:48 Kees Cook
0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2019-02-12 21:48 UTC (permalink / raw)
To: linux-kernel; +Cc: Yue Hu, Anton Vorontsov, Colin Cross, Tony Luck
Since the header is a fixed small maximum size, just use a stack variable
to avoid memory allocation in the write path.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
fs/pstore/ram.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index ec0e1da0596a..c5c685589e36 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -345,19 +345,15 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
struct pstore_record *record)
{
- char *hdr;
+ char hdr[36]; /* "===="(4), %lld(20), "."(1), %06lu(6), "-%c\n"(3) */
size_t len;
- hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n",
+ len = scnprintf(hdr, sizeof(hdr),
+ RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n",
(time64_t)record->time.tv_sec,
record->time.tv_nsec / 1000,
record->compressed ? 'C' : 'D');
- if (WARN_ON_ONCE(!hdr))
- return 0;
-
- len = strlen(hdr);
persistent_ram_write(prz, hdr, len);
- kfree(hdr);
return len;
}
--
2.17.1
--
Kees Cook
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-02-12 21:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-12 21:48 [PATCH] pstore/ram: Avoid needless alloc during header write Kees Cook
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.