Skip to content

Commit

Permalink
lightnvm: fix ioctl memory leaks
Browse files Browse the repository at this point in the history
If copy_to_user() fails we returned error but we missed releasing
devices.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Sudip Mukherjee authored and Jens Axboe committed Nov 29, 2015
1 parent 8261bd4 commit 76e2508
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/lightnvm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,10 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
info->tgtsize = tgt_iter;
up_write(&nvm_lock);

if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info)))
if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) {
kfree(info);
return -EFAULT;
}

kfree(info);
return 0;
Expand Down Expand Up @@ -724,8 +726,11 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)

devices->nr_devices = i;

if (copy_to_user(arg, devices, sizeof(struct nvm_ioctl_get_devices)))
if (copy_to_user(arg, devices,
sizeof(struct nvm_ioctl_get_devices))) {
kfree(devices);
return -EFAULT;
}

kfree(devices);
return 0;
Expand Down

0 comments on commit 76e2508

Please sign in to comment.