Commit f81259c6 authored by Yang Yingliang's avatar Yang Yingliang Committed by Andrew Morton

fail_function: switch to memdup_user_nul() helper

Use memdup_user_nul() helper instead of open-coding to simplify the code.

Link: https://lkml.kernel.org/r/20220826073337.2085798-1-yangyingliang@huawei.comSigned-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 9a15193e
...@@ -247,15 +247,11 @@ static ssize_t fei_write(struct file *file, const char __user *buffer, ...@@ -247,15 +247,11 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
/* cut off if it is too long */ /* cut off if it is too long */
if (count > KSYM_NAME_LEN) if (count > KSYM_NAME_LEN)
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)) { buf = memdup_user_nul(buffer, count);
ret = -EFAULT; if (IS_ERR(buf))
goto out_free; return PTR_ERR(buf);
}
buf[count] = '\0';
sym = strstrip(buf); sym = strstrip(buf);
mutex_lock(&fei_lock); mutex_lock(&fei_lock);
...@@ -308,7 +304,6 @@ static ssize_t fei_write(struct file *file, const char __user *buffer, ...@@ -308,7 +304,6 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
} }
out: out:
mutex_unlock(&fei_lock); mutex_unlock(&fei_lock);
out_free:
kfree(buf); kfree(buf);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment