summaryrefslogtreecommitdiffstats
path: root/fs/pstore/ram.c
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2019-02-12 22:09:36 +0100
committerKees Cook <keescook@chromium.org>2019-02-12 22:45:53 +0100
commit93ee4b7d9f0632690713aee604c49e298e634094 (patch)
treeb59d6703ee660577abbb1f3de464f2482a6962da /fs/pstore/ram.c
parentpstore/ram: Add kmsg hlen zero check to ramoops_pstore_write() (diff)
downloadlinux-93ee4b7d9f0632690713aee604c49e298e634094.tar.xz
linux-93ee4b7d9f0632690713aee604c49e298e634094.zip
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: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'fs/pstore/ram.c')
-rw-r--r--fs/pstore/ram.c10
1 files 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 @@ out:
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;
}