projects
/
linux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
9a15193
)
fail_function: switch to memdup_user_nul() helper
author
Yang Yingliang
<yangyingliang@huawei.com>
Fri, 26 Aug 2022 07:33:35 +0000
(15:33 +0800)
committer
Andrew Morton
<akpm@linux-foundation.org>
Mon, 12 Sep 2022 04:55:10 +0000
(21:55 -0700)
Use memdup_user_nul() helper instead of open-coding to simplify the code.
Link:
https://lkml.kernel.org/r/20220826073337.2085798-1-yangyingliang@huawei.com
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/fail_function.c
patch
|
blob
|
history
diff --git
a/kernel/fail_function.c
b/kernel/fail_function.c
index 60dc825ecc2b31ee3add395282fc79cf1e8c5f3d..03643e33e4c330b33b92913759de360ab73500df 100644
(file)
--- a/
kernel/fail_function.c
+++ b/
kernel/fail_function.c
@@
-247,15
+247,11
@@
static ssize_t fei_write(struct file *file, const char __user *buffer,
/* cut off if it is too long */
if (count > KSYM_NAME_LEN)
count = KSYM_NAME_LEN;
- buf = kmalloc(count + 1, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
- if (copy_from_user(buf, buffer, count)) {
- ret = -EFAULT;
- goto out_free;
- }
- buf[count] = '\0';
+ buf = memdup_user_nul(buffer, count);
+ if (IS_ERR(buf))
+ return PTR_ERR(buf);
+
sym = strstrip(buf);
mutex_lock(&fei_lock);
@@
-308,7
+304,6
@@
static ssize_t fei_write(struct file *file, const char __user *buffer,
}
out:
mutex_unlock(&fei_lock);
-out_free:
kfree(buf);
return ret;
}