From: Geliang Tang <geliangtang@gmail.com>
To: David Airlie <airlied@linux.ie>
Cc: Geliang Tang <geliangtang@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] agp: use memdup_user
Date: Sat, 6 May 2017 23:42:15 +0800 [thread overview]
Message-ID: <df8091d4c64a0d5a7ab0a5989f34552a5eebd15e.1493778999.git.geliangtang@gmail.com> (raw)
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
drivers/char/agp/compat_ioctl.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
index 2053f70..a0a3cf0 100644
--- a/drivers/char/agp/compat_ioctl.c
+++ b/drivers/char/agp/compat_ioctl.c
@@ -98,9 +98,10 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
if (ureserve.seg_count >= 16384)
return -EINVAL;
- usegment = kmalloc(sizeof(*usegment) * ureserve.seg_count, GFP_KERNEL);
- if (!usegment)
- return -ENOMEM;
+ usegment = memdup_user((void __user *)ureserve.seg_list,
+ sizeof(*usegment) * ureserve.seg_count);
+ if (IS_ERR(usegment))
+ return PTR_ERR(usegment);
ksegment = kmalloc(sizeof(*ksegment) * kreserve.seg_count, GFP_KERNEL);
if (!ksegment) {
@@ -108,13 +109,6 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
return -ENOMEM;
}
- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
- sizeof(*usegment) * ureserve.seg_count)) {
- kfree(usegment);
- kfree(ksegment);
- return -EFAULT;
- }
-
for (seg = 0; seg < ureserve.seg_count; seg++) {
ksegment[seg].pg_start = usegment[seg].pg_start;
ksegment[seg].pg_count = usegment[seg].pg_count;
--
2.9.3
next reply other threads:[~2017-05-06 15:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-06 15:42 Geliang Tang [this message]
2017-05-06 15:42 ` [PATCH] net/hippi/rrunner: " Geliang Tang
2017-05-08 19:02 ` David Miller
2017-05-06 15:42 ` [PATCH] spi: spidev: " Geliang Tang
2017-05-08 9:28 ` Geert Uytterhoeven
2017-05-15 8:05 ` Applied "spi: spidev: use memdup_user" to the spi tree Mark Brown
2017-05-06 15:42 ` [PATCH] usb: cdc-wdm: use memdup_user Geliang Tang
2017-05-06 17:40 ` Bjørn Mork
2017-05-08 15:14 ` [PATCH v2] " Geliang Tang
2017-05-09 7:50 ` Oliver Neukum
2017-05-06 15:42 ` [PATCH] wil6210: " Geliang Tang
2017-05-19 7:55 ` Kalle Valo
2017-05-06 15:42 ` [PATCH] wlcore: " Geliang Tang
2017-05-18 13:41 ` Kalle Valo
2017-05-06 15:42 ` [PATCH] xfrm: " Geliang Tang
2017-05-16 9:30 ` Steffen Klassert
2017-05-06 15:42 ` [PATCH] yam: " Geliang Tang
2017-05-08 19:02 ` David Miller
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=df8091d4c64a0d5a7ab0a5989f34552a5eebd15e.1493778999.git.geliangtang@gmail.com \
--to=geliangtang@gmail.com \
--cc=airlied@linux.ie \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®