Skip to content

Commit

Permalink
media: camss: fix memory leaks on error handling paths in probe
Browse files Browse the repository at this point in the history
camss_probe() does not free camss on error handling paths. The patch
introduces an additional error label for this purpose. Besides, it
removes call of v4l2_async_notifier_cleanup() from
camss_of_parse_ports() since its caller, camss_probe(), cleans up all
its resources itself.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Evgeny Novikov <[email protected]>
Co-developed-by: Anton Vasilyev <[email protected]>
Signed-off-by: Anton Vasilyev <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
eunovm authored and sigmaris committed Aug 8, 2020
1 parent ebb26f8 commit 8af4d9a
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions drivers/media/platform/qcom/camss/camss.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ static int camss_of_parse_ports(struct camss *camss)
return num_subdevs;

err_cleanup:
v4l2_async_notifier_cleanup(&camss->notifier);
of_node_put(node);
return ret;
}
Expand Down Expand Up @@ -835,29 +834,38 @@ static int camss_probe(struct platform_device *pdev)
camss->csid_num = 4;
camss->vfe_num = 2;
} else {
return -EINVAL;
ret = -EINVAL;
goto err_free;
}

camss->csiphy = devm_kcalloc(dev, camss->csiphy_num,
sizeof(*camss->csiphy), GFP_KERNEL);
if (!camss->csiphy)
return -ENOMEM;
if (!camss->csiphy) {
ret = -ENOMEM;
goto err_free;
}

camss->csid = devm_kcalloc(dev, camss->csid_num, sizeof(*camss->csid),
GFP_KERNEL);
if (!camss->csid)
return -ENOMEM;
if (!camss->csid) {
ret = -ENOMEM;
goto err_free;
}

camss->vfe = devm_kcalloc(dev, camss->vfe_num, sizeof(*camss->vfe),
GFP_KERNEL);
if (!camss->vfe)
return -ENOMEM;
if (!camss->vfe) {
ret = -ENOMEM;
goto err_free;
}

v4l2_async_notifier_init(&camss->notifier);

num_subdevs = camss_of_parse_ports(camss);
if (num_subdevs < 0)
return num_subdevs;
if (num_subdevs < 0) {
ret = num_subdevs;
goto err_cleanup;
}

ret = camss_init_subdevices(camss);
if (ret < 0)
Expand Down Expand Up @@ -936,6 +944,8 @@ static int camss_probe(struct platform_device *pdev)
v4l2_device_unregister(&camss->v4l2_dev);
err_cleanup:
v4l2_async_notifier_cleanup(&camss->notifier);
err_free:
kfree(camss);

return ret;
}
Expand Down

0 comments on commit 8af4d9a

Please sign in to comment.