From: Wan Jiabing <wanjiabing@vivo.com>
To: Larry Finger <Larry.Finger@lwfinger.net>,
Phillip Potter <phil@philpotter.co.uk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Michael Straube <straube.linux@gmail.com>,
Martin Kaiser <martin@kaiser.cx>,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: kael_w@yeah.net, Wan Jiabing <wanjiabing@vivo.com>
Subject: [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
Date: Thu, 21 Oct 2021 08:20:02 -0400 [thread overview]
Message-ID: <20211021122015.6974-1-wanjiabing@vivo.com> (raw)
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
next reply other threads:[~2021-10-21 12:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 12:20 Wan Jiabing [this message]
-- strict thread matches above, loose matches on Subject: below --
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
2021-12-10 3:38 Jiapeng Chong
2021-12-10 8:30 ` Dan Carpenter
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=20211021122015.6974-1-wanjiabing@vivo.com \
--to=wanjiabing@vivo.com \
--cc=Larry.Finger@lwfinger.net \
--cc=gregkh@linuxfoundation.org \
--cc=kael_w@yeah.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=martin@kaiser.cx \
--cc=phil@philpotter.co.uk \
--cc=straube.linux@gmail.com \
/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