Skip to content

Commit f45882c

Browse files
eunovmmchehab
authored andcommitted
media: camss: fix memory leaks on error handling paths in probe
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]>
1 parent 602649e commit f45882c

File tree

1 file changed

+20
-10
lines changed
  • drivers/media/platform/qcom/camss

1 file changed

+20
-10
lines changed

drivers/media/platform/qcom/camss/camss.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@ static int camss_of_parse_ports(struct camss *camss)
504504
return num_subdevs;
505505

506506
err_cleanup:
507-
v4l2_async_notifier_cleanup(&camss->notifier);
508507
of_node_put(node);
509508
return ret;
510509
}
@@ -835,29 +834,38 @@ static int camss_probe(struct platform_device *pdev)
835834
camss->csid_num = 4;
836835
camss->vfe_num = 2;
837836
} else {
838-
return -EINVAL;
837+
ret = -EINVAL;
838+
goto err_free;
839839
}
840840

841841
camss->csiphy = devm_kcalloc(dev, camss->csiphy_num,
842842
sizeof(*camss->csiphy), GFP_KERNEL);
843-
if (!camss->csiphy)
844-
return -ENOMEM;
843+
if (!camss->csiphy) {
844+
ret = -ENOMEM;
845+
goto err_free;
846+
}
845847

846848
camss->csid = devm_kcalloc(dev, camss->csid_num, sizeof(*camss->csid),
847849
GFP_KERNEL);
848-
if (!camss->csid)
849-
return -ENOMEM;
850+
if (!camss->csid) {
851+
ret = -ENOMEM;
852+
goto err_free;
853+
}
850854

851855
camss->vfe = devm_kcalloc(dev, camss->vfe_num, sizeof(*camss->vfe),
852856
GFP_KERNEL);
853-
if (!camss->vfe)
854-
return -ENOMEM;
857+
if (!camss->vfe) {
858+
ret = -ENOMEM;
859+
goto err_free;
860+
}
855861

856862
v4l2_async_notifier_init(&camss->notifier);
857863

858864
num_subdevs = camss_of_parse_ports(camss);
859-
if (num_subdevs < 0)
860-
return num_subdevs;
865+
if (num_subdevs < 0) {
866+
ret = num_subdevs;
867+
goto err_cleanup;
868+
}
861869

862870
ret = camss_init_subdevices(camss);
863871
if (ret < 0)
@@ -936,6 +944,8 @@ static int camss_probe(struct platform_device *pdev)
936944
v4l2_device_unregister(&camss->v4l2_dev);
937945
err_cleanup:
938946
v4l2_async_notifier_cleanup(&camss->notifier);
947+
err_free:
948+
kfree(camss);
939949

940950
return ret;
941951
}

0 commit comments

Comments
 (0)