From: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
To: Larry.Finger@lwfinger.net
Cc: phil@philpotter.co.uk, gregkh@linuxfoundation.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
Jiapeng Chong <jiapeng.chong@linux.alibaba.com>,
Abaci Robot <abaci@linux.alibaba.com>
Subject: [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
Date: Fri, 10 Dec 2021 11:38:32 +0800 [thread overview]
Message-ID: <20211210033832.40428-1-jiapeng.chong@linux.alibaba.com> (raw)
Fix following coccicheck warning:
./drivers/staging/r8188eu/os_dep/ioctl_linux.c:4253:8-15: WARNING
opportunity for memdup_user.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
drivers/staging/r8188eu/os_dep/ioctl_linux.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/r8188eu/os_dep/ioctl_linux.c b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
index 56adfe4087a8..c6a2fbfe8f26 100644
--- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
@@ -4250,17 +4250,12 @@ static int rtw_test(
DBG_88E("+%s\n", __func__);
len = wrqu->data.length;
- pbuf = kzalloc(len, GFP_KERNEL);
- if (!pbuf) {
- DBG_88E("%s: no memory!\n", __func__);
- return -ENOMEM;
- }
-
- if (copy_from_user(pbuf, wrqu->data.pointer, len)) {
- kfree(pbuf);
+ pbuf = memdup_user(wrqu->data.pointer, len);
+ if (IS_ERR(pbuf)) {
DBG_88E("%s: copy from user fail!\n", __func__);
- return -EFAULT;
+ return PTR_ERR(pbuf);
}
+
DBG_88E("%s: string =\"%s\"\n", __func__, pbuf);
ptmp = (char *)pbuf;
--
2.34.0
next reply other threads:[~2021-12-10 3:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-10 3:38 Jiapeng Chong [this message]
2021-12-10 8:30 ` [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user Dan Carpenter
-- strict thread matches above, loose matches on Subject: below --
2021-10-22 2:55 Kai Song
2021-10-22 9:07 ` Greg KH
2021-10-21 12:20 Wan Jiabing
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=20211210033832.40428-1-jiapeng.chong@linux.alibaba.com \
--to=jiapeng.chong@linux.alibaba.com \
--cc=Larry.Finger@lwfinger.net \
--cc=abaci@linux.alibaba.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=phil@philpotter.co.uk \
/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