diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 2d1066ed3c28..75887a269b64 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -501,6 +501,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 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);