Skip to content

Commit

Permalink
Input: joydev - use memdup_user() to duplicate memory from user-space
Browse files Browse the repository at this point in the history
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: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
  • Loading branch information
Javier Martinez Canillas authored and Dmitry Torokhov committed Oct 2, 2015
1 parent aaa59e0 commit 5702222
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions drivers/input/joydev.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,9 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev,
len = min(len, sizeof(joydev->abspam));

/* Validate the map. */
abspam = kmalloc(len, GFP_KERNEL);
if (!abspam)
return -ENOMEM;

if (copy_from_user(abspam, argp, len)) {
retval = -EFAULT;
abspam = memdup_user(argp, len);
if (IS_ERR(abspam)) {
retval = PTR_ERR(abspam);
goto out;
}

Expand Down Expand Up @@ -480,12 +477,9 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev,
len = min(len, sizeof(joydev->keypam));

/* Validate the map. */
keypam = kmalloc(len, GFP_KERNEL);
if (!keypam)
return -ENOMEM;

if (copy_from_user(keypam, argp, len)) {
retval = -EFAULT;
keypam = memdup_user(argp, len);
if (IS_ERR(keypam)) {
retval = PTR_ERR(keypam);
goto out;
}

Expand Down

0 comments on commit 5702222

Please sign in to comment.