diff options
author | Alexandre Bounine <alexandre.bounine@idt.com> | 2016-10-11 16:53:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-11 18:06:32 -0400 |
commit | 7836a2d9803c6203d2922e7116307c9f0dfe87f9 (patch) | |
tree | e9d75c25990f59db0dd18d4b6b27d162a724fab2 /drivers/rapidio/rio_cm.c | |
parent | 0a5bf409d3eefc1ca64cedf0bc1c0673164cacc1 (diff) |
rapidio/rio_cm: use memdup_user() instead of duplicating code
Fix coccinelle warning about duplicating existing memdup_user function.
Link: http://lkml.kernel.org/r/20160811151737.20140-1-alexandre.bounine@idt.com
Link: https://lkml.org/lkml/2016/8/11/29
Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com>
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: Andre van Herk <andre.van.herk@prodrive-technologies.com>
Cc: Barry Wood <barry.wood@idt.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rapidio/rio_cm.c')
-rw-r--r-- | drivers/rapidio/rio_cm.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/drivers/rapidio/rio_cm.c b/drivers/rapidio/rio_cm.c index cebc296463ad..bad0e0ea4f30 100644 --- a/drivers/rapidio/rio_cm.c +++ b/drivers/rapidio/rio_cm.c | |||
@@ -1841,24 +1841,19 @@ static int cm_chan_msg_send(void __user *arg) | |||
1841 | { | 1841 | { |
1842 | struct rio_cm_msg msg; | 1842 | struct rio_cm_msg msg; |
1843 | void *buf; | 1843 | void *buf; |
1844 | int ret = 0; | 1844 | int ret; |
1845 | 1845 | ||
1846 | if (copy_from_user(&msg, arg, sizeof(msg))) | 1846 | if (copy_from_user(&msg, arg, sizeof(msg))) |
1847 | return -EFAULT; | 1847 | return -EFAULT; |
1848 | if (msg.size > RIO_MAX_MSG_SIZE) | 1848 | if (msg.size > RIO_MAX_MSG_SIZE) |
1849 | return -EINVAL; | 1849 | return -EINVAL; |
1850 | 1850 | ||
1851 | buf = kmalloc(msg.size, GFP_KERNEL); | 1851 | buf = memdup_user((void __user *)(uintptr_t)msg.msg, msg.size); |
1852 | if (!buf) | 1852 | if (IS_ERR(buf)) |
1853 | return -ENOMEM; | 1853 | return PTR_ERR(buf); |
1854 | |||
1855 | if (copy_from_user(buf, (void __user *)(uintptr_t)msg.msg, msg.size)) { | ||
1856 | ret = -EFAULT; | ||
1857 | goto out; | ||
1858 | } | ||
1859 | 1854 | ||
1860 | ret = riocm_ch_send(msg.ch_num, buf, msg.size); | 1855 | ret = riocm_ch_send(msg.ch_num, buf, msg.size); |
1861 | out: | 1856 | |
1862 | kfree(buf); | 1857 | kfree(buf); |
1863 | return ret; | 1858 | return ret; |
1864 | } | 1859 | } |