powerpc/nvram: use memdup_user

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

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
Geliang Tang 2017-04-29 09:45:13 +08:00 committed by Kees Cook
parent 077090af33
commit 0752e4028c

View File

@ -792,21 +792,17 @@ static ssize_t dev_nvram_write(struct file *file, const char __user *buf,
count = min_t(size_t, count, size - *ppos); count = min_t(size_t, count, size - *ppos);
count = min(count, PAGE_SIZE); count = min(count, PAGE_SIZE);
ret = -ENOMEM; tmp = memdup_user(buf, count);
tmp = kmalloc(count, GFP_KERNEL); if (IS_ERR(tmp)) {
if (!tmp) ret = PTR_ERR(tmp);
goto out;
ret = -EFAULT;
if (copy_from_user(tmp, buf, count))
goto out; goto out;
}
ret = ppc_md.nvram_write(tmp, count, ppos); ret = ppc_md.nvram_write(tmp, count, ppos);
out:
kfree(tmp); kfree(tmp);
out:
return ret; return ret;
} }
static long dev_nvram_ioctl(struct file *file, unsigned int cmd, static long dev_nvram_ioctl(struct file *file, unsigned int cmd,