diff options
author | Yue Hu <huyue2@yulong.com> | 2019-01-31 11:12:46 +0100 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2019-02-12 21:09:49 +0100 |
commit | 4c6c4d34536744f2c9e171ef5bb548a06a525501 (patch) | |
tree | b796fdf12b0b4b29b9490dd157c6e40a2f8cd92a /fs/pstore/ram.c | |
parent | pstore/ram: Replace dummy_data heap memory with stack memory (diff) | |
download | linux-4c6c4d34536744f2c9e171ef5bb548a06a525501.tar.xz linux-4c6c4d34536744f2c9e171ef5bb548a06a525501.zip |
pstore: Avoid writing records with zero size
Sometimes pstore_console_write() will write records with zero size
to persistent ram zone, which is unnecessary. It will only increase
resource consumption. Also adjust ramoops_write_kmsg_hdr() to have
same logic if memory allocation fails.
Signed-off-by: Yue Hu <huyue2@yulong.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'fs/pstore/ram.c')
-rw-r--r-- | fs/pstore/ram.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 1adb5e35c004..b2471d430048 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -352,8 +352,10 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz, (time64_t)record->time.tv_sec, record->time.tv_nsec / 1000, record->compressed ? 'C' : 'D'); - WARN_ON_ONCE(!hdr); - len = hdr ? strlen(hdr) : 0; + if (WARN_ON_ONCE(!hdr)) + return 0; + + len = strlen(hdr); persistent_ram_write(prz, hdr, len); kfree(hdr); |