From: Muhammad Falak R Wani <falakreyaz@gmail.com>
To: <kas@fi.muni.cz>
Cc: netdev@vger.kernel.org (open list:NETWORKING DRIVERS),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] wan: cosa: use memdup_user().
Date: Fri, 20 May 2016 17:50:06 +0530 [thread overview]
Message-ID: <1463746806-23739-1-git-send-email-falakreyaz@gmail.com> (raw)
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
next reply other threads:[~2016-05-20 12:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-20 12:20 Muhammad Falak R Wani [this message]
2016-05-23 21:02 ` [PATCH] wan: cosa: use memdup_user() David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1463746806-23739-1-git-send-email-falakreyaz@gmail.com \
--to=falakreyaz@gmail.com \
--cc=kas@fi.muni.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).