Skip to content

Commit

Permalink
[media] lirc: fix error paths in lirc_cdev_add()
Browse files Browse the repository at this point in the history
"c77d17c0 [media] lirc: use-after free" introduces two problems:
cdev_del() can be called with a NULL argument, and the kobject_put()
path will cause a double free.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
  • Loading branch information
Sean Young authored and Mauro Carvalho Chehab committed Dec 1, 2016
1 parent 0036113 commit b40769e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions drivers/media/rc/lirc_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ static const struct file_operations lirc_dev_fops = {

static int lirc_cdev_add(struct irctl *ir)
{
int retval = -ENOMEM;
struct lirc_driver *d = &ir->d;
struct cdev *cdev;
int retval;

cdev = cdev_alloc();
if (!cdev)
goto err_out;
return -ENOMEM;

if (d->fops) {
cdev->ops = d->fops;
Expand All @@ -177,10 +177,8 @@ static int lirc_cdev_add(struct irctl *ir)
goto err_out;

retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1);
if (retval) {
kobject_put(&cdev->kobj);
if (retval)
goto err_out;
}

ir->cdev = cdev;

Expand Down

0 comments on commit b40769e

Please sign in to comment.