Re: [PATCH] platform/x86: toshiba_acpi: use memdup_user_nul

From: Andy Shevchenko
Date: Sun May 07 2017 - 17:38:54 EST


On Sat, May 6, 2017 at 6:40 PM, Geliang Tang <geliangtang@xxxxxxxxx> wrote:
> Use memdup_user_nul() helper instead of open-coding to simplify the
> code.
>

Pushed to testing, thanks.

> Signed-off-by: Geliang Tang <geliangtang@xxxxxxxxx>
> ---
> drivers/platform/x86/toshiba_acpi.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
> index d0daf75..88f9f79 100644
> --- a/drivers/platform/x86/toshiba_acpi.c
> +++ b/drivers/platform/x86/toshiba_acpi.c
> @@ -1502,14 +1502,9 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf,
> int ret;
> u32 video_out;
>
> - cmd = kmalloc(count + 1, GFP_KERNEL);
> - if (!cmd)
> - return -ENOMEM;
> - if (copy_from_user(cmd, buf, count)) {
> - kfree(cmd);
> - return -EFAULT;
> - }
> - cmd[count] = '\0';
> + cmd = memdup_user_nul(buf, count);
> + if (IS_ERR(cmd))
> + return PTR_ERR(cmd);
>
> buffer = cmd;
>
> --
> 2.9.3
>



--
With Best Regards,
Andy Shevchenko