Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1468478 > unrolled thread

[PATCH] staging: i4l: icn: use memdup_user

Started bySudip Mukherjee <sudipm.mukherjee@gmail.com>
First post2016-08-23 12:50 +0200
Last post2016-08-23 13:00 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] staging: i4l: icn: use memdup_user Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2016-08-23 12:50 +0200
    Re: [PATCH] staging: i4l: icn: use memdup_user Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2016-08-23 13:00 +0200
      Re: [PATCH] staging: i4l: icn: use memdup_user Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-08-23 15:10 +0200
    Re: [PATCH] staging: i4l: icn: use memdup_user Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-08-23 13:00 +0200

#1468478 — [PATCH] staging: i4l: icn: use memdup_user

FromSudip Mukherjee <sudipm.mukherjee@gmail.com>
Date2016-08-23 12:50 +0200
Subject[PATCH] staging: i4l: icn: use memdup_user
Message-ID<s9hrj-2PE-7@gated-at.bofh.it>
Its better to use memdup_user which does the same thing which this
code has implemented.

Suggested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---
 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;
 	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");
+		return PTR_ERR(codebuf);
 	}
 	if (!card->rvalid) {
 		if (!request_region(card->port, ICN_PORTLEN, card->regname)) {
@@ -902,7 +897,6 @@ icn_loadboot(u_char __user *buffer, icn_card *card)
 
 out_kfree:
 	kfree(codebuf);
-out:
 	return ret;
 }
 
-- 
1.9.1

[toc] | [next] | [standalone]


#1468479

FromSudip Mukherjee <sudipm.mukherjee@gmail.com>
Date2016-08-23 13:00 +0200
Message-ID<s9hAZ-2T7-3@gated-at.bofh.it>
In reply to#1468478
On Tue, Aug 23, 2016 at 06:50:30AM -0400, Greg Kroah-Hartman wrote:
> 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@intel.com>
> > Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
> > ---
> >  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?

type was changed as codebuf is only used with memdup_user() and
memcpy_toio() and both of them takes void. I should have mentioned
that in the commit message. Sending v2 with this change and after
removing the warning.

regards
sudip

[toc] | [prev] | [next] | [standalone]


#1468544

FromGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Date2016-08-23 15:10 +0200
Message-ID<s9jCN-4te-1@gated-at.bofh.it>
In reply to#1468479
On Tue, Aug 23, 2016 at 04:28:12PM +0530, Sudip Mukherjee wrote:
> On Tue, Aug 23, 2016 at 06:50:30AM -0400, Greg Kroah-Hartman wrote:
> > 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@intel.com>
> > > Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
> > > ---
> > >  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?
> 
> type was changed as codebuf is only used with memdup_user() and
> memcpy_toio() and both of them takes void. I should have mentioned
> that in the commit message. Sending v2 with this change and after
> removing the warning.

No, please leave the type alone, you are changing it for no good reason
(and in fact, it might be a bad change if anything else were to use that
pointer...)

greg k-h

[toc] | [prev] | [next] | [standalone]


#1468481

FromGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Date2016-08-23 13:00 +0200
Message-ID<s9hAZ-2T7-5@gated-at.bofh.it>
In reply to#1468478
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@intel.com>
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
> ---
>  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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web