linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
@ 2021-10-22  2:55 Kai Song
  2021-10-22  9:07 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Kai Song @ 2021-10-22  2:55 UTC (permalink / raw)
  To: gregkh
  Cc: Larry.Finger, phil, straube.linux, linux-staging, linux-kernel, Kai Song

Use memdup_user helper instead of open-coding to simplify
the code.

Signed-off-by: Kai Song <songkai01@inspur.com>
---
 drivers/staging/r8188eu/os_dep/ioctl_linux.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/r8188eu/os_dep/ioctl_linux.c b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
index 0201f6fbeb25..96a08cc5a1ed 100644
--- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
@@ -1984,14 +1984,10 @@ static int rtw_wx_read32(struct net_device *dev,
 	padapter = (struct adapter *)rtw_netdev_priv(dev);
 	p = &wrqu->data;
 	len = p->length;
-	ptmp = kmalloc(len, GFP_KERNEL);
-	if (!ptmp)
-		return -ENOMEM;
 
-	if (copy_from_user(ptmp, p->pointer, len)) {
-		kfree(ptmp);
-		return -EFAULT;
-	}
+	ptmp = memdup_user(p->pointer, len);
+	if (IS_ERR(ptmp))
+		return PTR_ERR(ptmp);
 
 	bytes = 0;
 	addr = 0;
-- 
2.27.0


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

* Re: [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
  2021-10-22  2:55 [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user Kai Song
@ 2021-10-22  9:07 ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2021-10-22  9:07 UTC (permalink / raw)
  To: Kai Song; +Cc: Larry.Finger, phil, straube.linux, linux-staging, linux-kernel

On Fri, Oct 22, 2021 at 10:55:55AM +0800, Kai Song wrote:
> Use memdup_user helper instead of open-coding to simplify
> the code.
> 
> Signed-off-by: Kai Song <songkai01@inspur.com>
> ---
>  drivers/staging/r8188eu/os_dep/ioctl_linux.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)

Someone sent this just before you did, sorry:
	https://lore.kernel.org/r/20211021122015.6974-1-wanjiabing@vivo.com


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

* [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
@ 2021-10-21 12:20 Wan Jiabing
  0 siblings, 0 replies; 3+ messages in thread
From: Wan Jiabing @ 2021-10-21 12:20 UTC (permalink / raw)
  To: Larry Finger, Phillip Potter, Greg Kroah-Hartman,
	Michael Straube, Martin Kaiser, linux-staging, linux-kernel
  Cc: kael_w, Wan Jiabing

Fix following coccicheck warning:
./drivers/staging/r8188eu/os_dep/ioctl_linux.c:1986:8-15: WARNING
opportunity for memdup_user.

Use memdup_user rather than duplicating its implementation, which
makes code simple and easy to understand.

Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
 drivers/staging/r8188eu/os_dep/ioctl_linux.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/r8188eu/os_dep/ioctl_linux.c b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
index 4f0ae821d193..301a29984fad 100644
--- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
@@ -1983,14 +1983,9 @@ static int rtw_wx_read32(struct net_device *dev,
 	padapter = (struct adapter *)rtw_netdev_priv(dev);
 	p = &wrqu->data;
 	len = p->length;
-	ptmp = kmalloc(len, GFP_KERNEL);
-	if (!ptmp)
-		return -ENOMEM;
-
-	if (copy_from_user(ptmp, p->pointer, len)) {
-		kfree(ptmp);
-		return -EFAULT;
-	}
+	ptmp = memdup_user(p->pointer, len);
+	if (IS_ERR(ptmp))
+		return PTR_ERR(ptmp);
 
 	bytes = 0;
 	addr = 0;
-- 
2.20.1


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

end of thread, other threads:[~2021-10-22  9:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-22  2:55 [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user Kai Song
2021-10-22  9:07 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2021-10-21 12:20 Wan Jiabing

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).