Commit 5702222c authored by Javier Martinez Canillas's avatar Javier Martinez Canillas Committed by Dmitry Torokhov

Input: joydev - use memdup_user() to duplicate memory from user-space

The memdup_user() helper function can be used to duplicate a memory region
from user-space to kernel-space. There is no need to open code the same
logic using kmalloc() and copy_from_user() instead. This was found with
make coccicheck that reported the following warning:

drivers/input/joydev.c:447:10-17: WARNING opportunity for memdup_user
drivers/input/joydev.c:483:10-17: WARNING opportunity for memdup_user
Signed-off-by: default avatarJavier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent aaa59e09
...@@ -444,12 +444,9 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev, ...@@ -444,12 +444,9 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev,
len = min(len, sizeof(joydev->abspam)); len = min(len, sizeof(joydev->abspam));
/* Validate the map. */ /* Validate the map. */
abspam = kmalloc(len, GFP_KERNEL); abspam = memdup_user(argp, len);
if (!abspam) if (IS_ERR(abspam)) {
return -ENOMEM; retval = PTR_ERR(abspam);
if (copy_from_user(abspam, argp, len)) {
retval = -EFAULT;
goto out; goto out;
} }
...@@ -480,12 +477,9 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev, ...@@ -480,12 +477,9 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev,
len = min(len, sizeof(joydev->keypam)); len = min(len, sizeof(joydev->keypam));
/* Validate the map. */ /* Validate the map. */
keypam = kmalloc(len, GFP_KERNEL); keypam = memdup_user(argp, len);
if (!keypam) if (IS_ERR(keypam)) {
return -ENOMEM; retval = PTR_ERR(keypam);
if (copy_from_user(keypam, argp, len)) {
retval = -EFAULT;
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment