Commit 93ee4b7d authored by Kees Cook's avatar Kees Cook

pstore/ram: Avoid needless alloc during header write

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: default avatarKees Cook <keescook@chromium.org>
parent 47afd7ae
...@@ -345,19 +345,15 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) ...@@ -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, static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
struct pstore_record *record) struct pstore_record *record)
{ {
char *hdr; char hdr[36]; /* "===="(4), %lld(20), "."(1), %06lu(6), "-%c\n"(3) */
size_t len; 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, (time64_t)record->time.tv_sec,
record->time.tv_nsec / 1000, record->time.tv_nsec / 1000,
record->compressed ? 'C' : 'D'); record->compressed ? 'C' : 'D');
if (WARN_ON_ONCE(!hdr))
return 0;
len = strlen(hdr);
persistent_ram_write(prz, hdr, len); persistent_ram_write(prz, hdr, len);
kfree(hdr);
return len; return len;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment