Skip to content

Commit ac56886

Browse files
Igor Matheus Andrade Torrentemchehab
authored andcommitted
media: em28xx: Fix possible memory leak of em28xx struct
The em28xx struct kref isn't being decreased after an error in the em28xx_ir_init, leading to a possible memory leak. A kref_put and em28xx_shutdown_buttons is added to the error handler code. Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent a3a54bf commit ac56886

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/media/usb/em28xx/em28xx-input.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ static int em28xx_ir_init(struct em28xx *dev)
720720
dev->board.has_ir_i2c = 0;
721721
dev_warn(&dev->intf->dev,
722722
"No i2c IR remote control device found.\n");
723-
return -ENODEV;
723+
err = -ENODEV;
724+
goto ref_put;
724725
}
725726
}
726727

@@ -735,7 +736,7 @@ static int em28xx_ir_init(struct em28xx *dev)
735736

736737
ir = kzalloc(sizeof(*ir), GFP_KERNEL);
737738
if (!ir)
738-
return -ENOMEM;
739+
goto ref_put;
739740
rc = rc_allocate_device(RC_DRIVER_SCANCODE);
740741
if (!rc)
741742
goto error;
@@ -839,6 +840,9 @@ static int em28xx_ir_init(struct em28xx *dev)
839840
dev->ir = NULL;
840841
rc_free_device(rc);
841842
kfree(ir);
843+
ref_put:
844+
em28xx_shutdown_buttons(dev);
845+
kref_put(&dev->ref, em28xx_free_device);
842846
return err;
843847
}
844848

0 commit comments

Comments
 (0)