Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1466802
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation |
| Date | 2016-08-20 10:40 +0200 |
| Message-ID | <s89YR-Aq-5@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 20 Aug 2016 10:10:12 +0200
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/net/wan/cosa.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index b87fe0a..02f5809 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -875,16 +875,10 @@ static ssize_t cosa_write(struct file *file,
if (count > COSA_MTU)
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);
--
2.9.3
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-20 10:40 +0200
Re: [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-08-20 10:50 +0200
Re: [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation David Miller <davem@davemloft.net> - 2016-08-21 04:20 +0200
Re: [PATCH] wan-cosa: Use memdup_user() rather than duplicating its implementation Jan Kasprzak <kas@fi.muni.cz> - 2016-08-24 17:40 +0200
Re: wan-cosa: Use memdup_user() rather than duplicating its implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-24 18:20 +0200
Re: wan-cosa: Use memdup_user() rather than duplicating its implementation Jan Kasprzak <kas@fi.muni.cz> - 2016-08-25 11:20 +0200
csiph-web