linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wan: cosa: use memdup_user().
@ 2016-05-20 12:20 Muhammad Falak R Wani
  2016-05-23 21:02 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Muhammad Falak R Wani @ 2016-05-20 12:20 UTC (permalink / raw)
  To: kas; +Cc: open list:NETWORKING DRIVERS, open list

Use memdup_user to duplicate a memory region from user-space to
kernel-space, instead of open coding using kmalloc & copy_from_user.

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
---
 drivers/net/wan/cosa.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index b87fe0a..fb37439 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -876,15 +876,10 @@ static ssize_t cosa_write(struct file *file,
 		count = COSA_MTU;
 	
 	/* Allocate the buffer */
-	kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
-	if (kbuf == NULL) {
+	kbuf = memdup_user(buf, count);
+	if (IS_ERR(kbuf)) {
 		up(&chan->wsem);
-		return -ENOMEM;
-	}
-	if (copy_from_user(kbuf, buf, count)) {
-		up(&chan->wsem);
-		kfree(kbuf);
-		return -EFAULT;
+		return PTR_ERR(kbuf);
 	}
 	chan->tx_status=0;
 	cosa_start_tx(chan, kbuf, count);
-- 
1.9.1

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

* Re: [PATCH] wan: cosa: use memdup_user().
  2016-05-20 12:20 [PATCH] wan: cosa: use memdup_user() Muhammad Falak R Wani
@ 2016-05-23 21:02 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-05-23 21:02 UTC (permalink / raw)
  To: falakreyaz; +Cc: kas, netdev, linux-kernel

From: Muhammad Falak R Wani <falakreyaz@gmail.com>
Date: Fri, 20 May 2016 17:50:06 +0530

> Use memdup_user to duplicate a memory region from user-space to
> kernel-space, instead of open coding using kmalloc & copy_from_user.
> 
> Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
> ---
>  drivers/net/wan/cosa.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
> index b87fe0a..fb37439 100644
> --- a/drivers/net/wan/cosa.c
> +++ b/drivers/net/wan/cosa.c
> @@ -876,15 +876,10 @@ static ssize_t cosa_write(struct file *file,
>  		count = COSA_MTU;
>  	
>  	/* Allocate the buffer */
> -	kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
> -	if (kbuf == NULL) {
> +	kbuf = memdup_user(buf, count);

You're losing the GFP_DMA specification here, therefore this change
is not correct.

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

end of thread, other threads:[~2016-05-23 21:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-20 12:20 [PATCH] wan: cosa: use memdup_user() Muhammad Falak R Wani
2016-05-23 21:02 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).