Skip to content

Commit 0ff0ae6

Browse files
mudonglianggregkh
authored andcommitted
media: em28xx: fix memory leak in em28xx_init_dev
[ Upstream commit 22be5a1 ] In the em28xx_init_rev, if em28xx_audio_setup fails, this function fails to deallocate the media_dev allocated in the em28xx_media_device_init. Fix this by adding em28xx_unregister_media_device to free media_dev. BTW, this patch is tested in my local syzkaller instance, and it can prevent the memory leak from occurring again. CC: Pavel Skripkin <paskripkin@gmail.com> Fixes: 37ecc7b ("[media] em28xx: add media controller support") Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> Reported-by: syzkaller <syzkaller@googlegroups.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b441d94 commit 0ff0ae6

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎drivers/media/usb/em28xx/em28xx-cards.c‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,8 +3575,10 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
35753575

35763576
if (dev->is_audio_only) {
35773577
retval = em28xx_audio_setup(dev);
3578-
if (retval)
3579-
return -ENODEV;
3578+
if (retval) {
3579+
retval = -ENODEV;
3580+
goto err_deinit_media;
3581+
}
35803582
em28xx_init_extension(dev);
35813583

35823584
return 0;
@@ -3595,7 +3597,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
35953597
dev_err(&dev->intf->dev,
35963598
"%s: em28xx_i2c_register bus 0 - error [%d]!\n",
35973599
__func__, retval);
3598-
return retval;
3600+
goto err_deinit_media;
35993601
}
36003602

36013603
/* register i2c bus 1 */
@@ -3611,16 +3613,20 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
36113613
"%s: em28xx_i2c_register bus 1 - error [%d]!\n",
36123614
__func__, retval);
36133615

3614-
em28xx_i2c_unregister(dev, 0);
3615-
3616-
return retval;
3616+
goto err_unreg_i2c;
36173617
}
36183618
}
36193619

36203620
/* Do board specific init and eeprom reading */
36213621
em28xx_card_setup(dev);
36223622

36233623
return 0;
3624+
3625+
err_unreg_i2c:
3626+
em28xx_i2c_unregister(dev, 0);
3627+
err_deinit_media:
3628+
em28xx_unregister_media_device(dev);
3629+
return retval;
36243630
}
36253631

36263632
static int em28xx_duplicate_dev(struct em28xx *dev)

0 commit comments

Comments
 (0)