linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] pstore/platform: check the return value of kstrdup()
@ 2021-12-13  8:16 Xiaoke Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Xiaoke Wang @ 2021-12-13  8:16 UTC (permalink / raw)
  To: keescook, anton, ccross, tony.luck; +Cc: linux-kernel, Xiaoke Wang

Note: Compare with the last email, this one is using my full name.
kstrdup() returns NULL when some internal memory errors happen, it is
better to checkk the return value of it. Otherwise, some memory errors
will not be catched in time and may also further result in wrong memory
access.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 fs/pstore/platform.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index b9614db..f7c8732 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -620,6 +620,11 @@ int pstore_register(struct pstore_info *psi)
 	 * through /sys/module/pstore/parameters/backend
 	 */
 	backend = kstrdup(psi->name, GFP_KERNEL);
+	if (!backend) {
+		pr_err("out of memory duplicating '%s'\n", psi->name);
+		mutex_unlock(&psinfo_lock);
+		return -ENOMEM;
+	}
 
 	pr_info("Registered %s as persistent store backend\n", psi->name);
 
-- 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] pstore/platform: check the return value of kstrdup()
@ 2021-12-12 17:16 xkernel
  0 siblings, 0 replies; 2+ messages in thread
From: xkernel @ 2021-12-12 17:16 UTC (permalink / raw)
  To: keescook, anton, ccross, tony.luck; +Cc: linux-kernel, xkernel

kstrdup() returns NULL when some internal memory errors happen, it is
better to check the return value of it. Otherwise, some memory errors
will not be catched in time and may also further result in wrong memory
access.

Signed-off-by: xkernel <xkernel.wang@foxmail.com>
---
 fs/pstore/platform.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index b9614db..f7c8732 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -620,6 +620,11 @@ int pstore_register(struct pstore_info *psi)
 	 * through /sys/module/pstore/parameters/backend
 	 */
 	backend = kstrdup(psi->name, GFP_KERNEL);
+	if (!backend) {
+		pr_err("out of memory duplicating '%s'\n", psi->name);
+		mutex_unlock(&psinfo_lock);
+		return -ENOMEM;
+	}
 
 	pr_info("Registered %s as persistent store backend\n", psi->name);
 
-- 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-13  8:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13  8:16 [PATCH] pstore/platform: check the return value of kstrdup() Xiaoke Wang
  -- strict thread matches above, loose matches on Subject: below --
2021-12-12 17:16 xkernel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).