Skip to contentSkip to conversation

wan: cosa: use memdup_user().

PATCH In review Muhammad Falak R Wani 2 participants 2 messages May 20, 2016 – May 23, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wan: cosa: use memdup_user().

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

---
 drivers/net/wan/cosa.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/wan/cosa.c +3 -8
index b87fe0a..fb37439 100644
@@ -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);
Signature · 1 line
1.9.1
maintainer
#1 lore raw

From: Muhammad Falak R Wani <[email protected]>
Date: Fri, 20 May 2016 17:50:06 +0530

Quoted 13 lines

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

---
 drivers/net/wan/cosa.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/wan/cosa.c +0 -0
index b87fe0a..fb37439 100644

drivers/net/wan/cosa.c static ssize_t cosa_write(struct file *file, · line 879

Quoted 6 lines
drivers/net/wan/cosa.c +1 -2
@@ -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.