提交 fc304ad5 编写于 作者: D Dongliang Mu 提交者: Zheng Zengkai

media: em28xx: fix memory leak in em28xx_init_dev

stable inclusion
from stable-v5.10.94
commit 0ff0ae69d27cfeb463b4452b74cebc52bdbd71e6
bugzilla: https://gitee.com/openeuler/kernel/issues/I531X9

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0ff0ae69d27cfeb463b4452b74cebc52bdbd71e6

--------------------------------

[ Upstream commit 22be5a10 ]

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: 37ecc7b1 ("[media] em28xx: add media controller support")
Signed-off-by: NDongliang Mu <mudongliangabcd@gmail.com>
Reported-by: Nsyzkaller <syzkaller@googlegroups.com>
Signed-off-by: NHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: NMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 9bdf63d7
...@@ -3575,8 +3575,10 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, ...@@ -3575,8 +3575,10 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
if (dev->is_audio_only) { if (dev->is_audio_only) {
retval = em28xx_audio_setup(dev); retval = em28xx_audio_setup(dev);
if (retval) if (retval) {
return -ENODEV; retval = -ENODEV;
goto err_deinit_media;
}
em28xx_init_extension(dev); em28xx_init_extension(dev);
return 0; return 0;
...@@ -3595,7 +3597,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, ...@@ -3595,7 +3597,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
dev_err(&dev->intf->dev, dev_err(&dev->intf->dev,
"%s: em28xx_i2c_register bus 0 - error [%d]!\n", "%s: em28xx_i2c_register bus 0 - error [%d]!\n",
__func__, retval); __func__, retval);
return retval; goto err_deinit_media;
} }
/* register i2c bus 1 */ /* register i2c bus 1 */
...@@ -3611,9 +3613,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, ...@@ -3611,9 +3613,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
"%s: em28xx_i2c_register bus 1 - error [%d]!\n", "%s: em28xx_i2c_register bus 1 - error [%d]!\n",
__func__, retval); __func__, retval);
em28xx_i2c_unregister(dev, 0); goto err_unreg_i2c;
return retval;
} }
} }
...@@ -3621,6 +3621,12 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, ...@@ -3621,6 +3621,12 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
em28xx_card_setup(dev); em28xx_card_setup(dev);
return 0; return 0;
err_unreg_i2c:
em28xx_i2c_unregister(dev, 0);
err_deinit_media:
em28xx_unregister_media_device(dev);
return retval;
} }
static int em28xx_duplicate_dev(struct em28xx *dev) static int em28xx_duplicate_dev(struct em28xx *dev)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册