[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <df8091d4c64a0d5a7ab0a5989f34552a5eebd15e.1493778999.git.geliangtang@gmail.com>
Date: Sat, 6 May 2017 23:42:15 +0800
From: Geliang Tang <geliangtang@...il.com>
To: David Airlie <airlied@...ux.ie>
Cc: Geliang Tang <geliangtang@...il.com>, linux-kernel@...r.kernel.org
Subject: [PATCH] agp: use memdup_user
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@...il.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
Powered by blists - more mailing lists