lkml.org 
[lkml]   [2017]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] agp: use memdup_user
Date
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
\
 
 \ /
  Last update: 2017-05-06 17:42    [W:0.112 / U:15.216 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site