Re: [PATCH] staging: i4l: icn: use memdup_user

From: Greg Kroah-Hartman
Date: Tue Aug 23 2016 - 06:50:26 EST


On Tue, Aug 23, 2016 at 03:57:34PM +0530, Sudip Mukherjee wrote:
> Its better to use memdup_user which does the same thing which this
> code has implemented.
>
> Suggested-by: Fengguang Wu <fengguang.wu@xxxxxxxxx>
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@xxxxxxxxxxxxxxx>
> ---
> drivers/staging/i4l/icn/icn.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/staging/i4l/icn/icn.c b/drivers/staging/i4l/icn/icn.c
> index b2f4055..5312675 100644
> --- a/drivers/staging/i4l/icn/icn.c
> +++ b/drivers/staging/i4l/icn/icn.c
> @@ -804,21 +804,16 @@ static int
> icn_loadboot(u_char __user *buffer, icn_card *card)
> {
> int ret;
> - u_char *codebuf;
> + void *codebuf;

why did you change the type here?


> unsigned long flags;
>
> #ifdef BOOT_DEBUG
> printk(KERN_DEBUG "icn_loadboot called, buffaddr=%08lx\n", (ulong) buffer);
> #endif
> - codebuf = kmalloc(ICN_CODE_STAGE1, GFP_KERNEL);
> - if (!codebuf) {
> - printk(KERN_WARNING "icn: Could not allocate code buffer\n");
> - ret = -ENOMEM;
> - goto out;
> - }
> - if (copy_from_user(codebuf, buffer, ICN_CODE_STAGE1)) {
> - ret = -EFAULT;
> - goto out_kfree;
> + codebuf = memdup_user(buffer, ICN_CODE_STAGE1);
> + if (IS_ERR(codebuf)) {
> + pr_warn("icn: Could not allocate code buffer\n");

Don't warn about something that already was warned about.

thanks,

greg k-h