From: Yue Hu
stable inclusion
from stable-5.10
category: feature
commit:4c6c4d34536744f2c9e171ef5bb548a06a525501
issue: #I4919J
--------------------------------
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
Signed-off-by: Kees Cook
(cherry picked from commit 4c6c4d34536744f2c9e171ef5bb548a06a525501)
Signed-off-by: roger
---
fs/pstore/platform.c | 3 +++
fs/pstore/ram.c | 6 ++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 7a873006d525..2a561728443f 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -520,6 +520,9 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
{
struct pstore_record record;
+ if (!c)
+ return;
+
pstore_record_init(&record, psinfo);
record.type = PSTORE_TYPE_CONSOLE;
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 2921905cb7e5..bc7af9393d8f 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -354,8 +354,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);
--
2.17.1