lkml.org 
[lkml]   [2021]   [Dec]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [PATCH] pstore/platform: check the return value of kstrdup()
Date
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);

--
\
 
 \ /
  Last update: 2021-12-13 09:18    [W:0.022 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site