Commit 9c39be40 authored by Pavel Skripkin's avatar Pavel Skripkin Committed by Mauro Carvalho Chehab

media: drivers/media/usb: fix memory leak in zr364xx_probe

syzbot reported memory leak in zr364xx_probe()[1].
The problem was in invalid error handling order.
All error conditions rigth after v4l2_ctrl_handler_init()
must call v4l2_ctrl_handler_free().

Reported-by: syzbot+efe9aefc31ae1e6f7675@syzkaller.appspotmail.com
Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 18a4ca76
...@@ -1430,7 +1430,7 @@ static int zr364xx_probe(struct usb_interface *intf, ...@@ -1430,7 +1430,7 @@ static int zr364xx_probe(struct usb_interface *intf,
if (hdl->error) { if (hdl->error) {
err = hdl->error; err = hdl->error;
dev_err(&udev->dev, "couldn't register control\n"); dev_err(&udev->dev, "couldn't register control\n");
goto unregister; goto free_hdlr_and_unreg_dev;
} }
/* save the init method used by this camera */ /* save the init method used by this camera */
cam->method = id->driver_info; cam->method = id->driver_info;
...@@ -1503,7 +1503,7 @@ static int zr364xx_probe(struct usb_interface *intf, ...@@ -1503,7 +1503,7 @@ static int zr364xx_probe(struct usb_interface *intf,
if (!cam->read_endpoint) { if (!cam->read_endpoint) {
err = -ENOMEM; err = -ENOMEM;
dev_err(&intf->dev, "Could not find bulk-in endpoint\n"); dev_err(&intf->dev, "Could not find bulk-in endpoint\n");
goto unregister; goto free_hdlr_and_unreg_dev;
} }
/* v4l */ /* v4l */
...@@ -1515,7 +1515,7 @@ static int zr364xx_probe(struct usb_interface *intf, ...@@ -1515,7 +1515,7 @@ static int zr364xx_probe(struct usb_interface *intf,
/* load zr364xx board specific */ /* load zr364xx board specific */
err = zr364xx_board_init(cam); err = zr364xx_board_init(cam);
if (err) if (err)
goto unregister; goto free_hdlr_and_unreg_dev;
err = v4l2_ctrl_handler_setup(hdl); err = v4l2_ctrl_handler_setup(hdl);
if (err) if (err)
goto board_uninit; goto board_uninit;
...@@ -1533,7 +1533,7 @@ static int zr364xx_probe(struct usb_interface *intf, ...@@ -1533,7 +1533,7 @@ static int zr364xx_probe(struct usb_interface *intf,
err = video_register_device(&cam->vdev, VFL_TYPE_VIDEO, -1); err = video_register_device(&cam->vdev, VFL_TYPE_VIDEO, -1);
if (err) { if (err) {
dev_err(&udev->dev, "video_register_device failed\n"); dev_err(&udev->dev, "video_register_device failed\n");
goto free_handler; goto board_uninit;
} }
cam->v4l2_dev.release = zr364xx_release; cam->v4l2_dev.release = zr364xx_release;
...@@ -1541,11 +1541,10 @@ static int zr364xx_probe(struct usb_interface *intf, ...@@ -1541,11 +1541,10 @@ static int zr364xx_probe(struct usb_interface *intf,
video_device_node_name(&cam->vdev)); video_device_node_name(&cam->vdev));
return 0; return 0;
free_handler:
v4l2_ctrl_handler_free(hdl);
board_uninit: board_uninit:
zr364xx_board_uninit(cam); zr364xx_board_uninit(cam);
unregister: free_hdlr_and_unreg_dev:
v4l2_ctrl_handler_free(hdl);
v4l2_device_unregister(&cam->v4l2_dev); v4l2_device_unregister(&cam->v4l2_dev);
free_cam: free_cam:
kfree(cam); kfree(cam);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment