Skip to content

Commit

Permalink
media: em28xx: Fix possible memory leak of em28xx struct
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
Igor Matheus Andrade Torrente authored and mchehab committed Jun 2, 2021
1 parent a3a54bf commit ac56886
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/media/usb/em28xx/em28xx-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ static int em28xx_ir_init(struct em28xx *dev)
dev->board.has_ir_i2c = 0;
dev_warn(&dev->intf->dev,
"No i2c IR remote control device found.\n");
return -ENODEV;
err = -ENODEV;
goto ref_put;
}
}

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

ir = kzalloc(sizeof(*ir), GFP_KERNEL);
if (!ir)
return -ENOMEM;
goto ref_put;
rc = rc_allocate_device(RC_DRIVER_SCANCODE);
if (!rc)
goto error;
Expand Down Expand Up @@ -839,6 +840,9 @@ static int em28xx_ir_init(struct em28xx *dev)
dev->ir = NULL;
rc_free_device(rc);
kfree(ir);
ref_put:
em28xx_shutdown_buttons(dev);
kref_put(&dev->ref, em28xx_free_device);
return err;
}

Expand Down

0 comments on commit ac56886

Please sign in to comment.