All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: i4l: icn: use memdup_user
@ 2016-08-23 10:27 Sudip Mukherjee
  2016-08-23 10:50 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Sudip Mukherjee @ 2016-08-23 10:27 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, devel, Sudip Mukherjee, Fengguang Wu

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] staging: i4l: icn: use memdup_user
  2016-08-23 10:27 [PATCH] staging: i4l: icn: use memdup_user Sudip Mukherjee
@ 2016-08-23 10:50 ` Greg Kroah-Hartman
  2016-08-23 10:58   ` Sudip Mukherjee
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2016-08-23 10:50 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: devel, Fengguang Wu, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] staging: i4l: icn: use memdup_user
  2016-08-23 10:50 ` Greg Kroah-Hartman
@ 2016-08-23 10:58   ` Sudip Mukherjee
  2016-08-23 13:07     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Sudip Mukherjee @ 2016-08-23 10:58 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, Fengguang Wu, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] staging: i4l: icn: use memdup_user
  2016-08-23 10:58   ` Sudip Mukherjee
@ 2016-08-23 13:07     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2016-08-23 13:07 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: devel, Fengguang Wu, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-23 13:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-23 10:27 [PATCH] staging: i4l: icn: use memdup_user Sudip Mukherjee
2016-08-23 10:50 ` Greg Kroah-Hartman
2016-08-23 10:58   ` Sudip Mukherjee
2016-08-23 13:07     ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.