Skip to content

Commit 22be5a1

Browse files
mudongliangmchehab
authored andcommitted
media: em28xx: fix memory leak in em28xx_init_dev
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>
1 parent 91bd11a commit 22be5a1

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
@@ -3630,8 +3630,10 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
36303630

36313631
if (dev->is_audio_only) {
36323632
retval = em28xx_audio_setup(dev);
3633-
if (retval)
3634-
return -ENODEV;
3633+
if (retval) {
3634+
retval = -ENODEV;
3635+
goto err_deinit_media;
3636+
}
36353637
em28xx_init_extension(dev);
36363638

36373639
return 0;
@@ -3650,7 +3652,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
36503652
dev_err(&dev->intf->dev,
36513653
"%s: em28xx_i2c_register bus 0 - error [%d]!\n",
36523654
__func__, retval);
3653-
return retval;
3655+
goto err_deinit_media;
36543656
}
36553657

36563658
/* register i2c bus 1 */
@@ -3666,16 +3668,20 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
36663668
"%s: em28xx_i2c_register bus 1 - error [%d]!\n",
36673669
__func__, retval);
36683670

3669-
em28xx_i2c_unregister(dev, 0);
3670-
3671-
return retval;
3671+
goto err_unreg_i2c;
36723672
}
36733673
}
36743674

36753675
/* Do board specific init and eeprom reading */
36763676
em28xx_card_setup(dev);
36773677

36783678
return 0;
3679+
3680+
err_unreg_i2c:
3681+
em28xx_i2c_unregister(dev, 0);
3682+
err_deinit_media:
3683+
em28xx_unregister_media_device(dev);
3684+
return retval;
36793685
}
36803686

36813687
static int em28xx_duplicate_dev(struct em28xx *dev)

0 commit comments

Comments
 (0)