In some places in we put an error into a local Error*, but forget to check for failure and pass it back to the caller. Add a Coccinelle patch to catch automatically add the missing code.
Inspired-by: Peter Maydell <peter.mayd...@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> --- ...ect_property_missing_error_propagate.cocci | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 scripts/coccinelle/object_property_missing_error_propagate.cocci diff --git a/scripts/coccinelle/object_property_missing_error_propagate.cocci b/scripts/coccinelle/object_property_missing_error_propagate.cocci new file mode 100644 index 0000000000..104e345273 --- /dev/null +++ b/scripts/coccinelle/object_property_missing_error_propagate.cocci @@ -0,0 +1,58 @@ +// Add missing error-propagation code +// +// Copyright: (C) 2020 Philippe Mathieu-Daudé. +// This work is licensed under the terms of the GNU GPLv2 or later. +// +// spatch \ +// --macro-file scripts/cocci-macro-file.h --include-headers \ +// --sp-file scripts/coccinelle/object_property_missing_error_propagate.cocci \ +// --keep-comments --smpl-spacing --in-place --dir hw +// +// Inspired by https://www.mail-archive.com/qemu-devel@nongnu.org/msg691638.html + +@match exists@ +typedef Error; +Error *err; +identifier func, errp; +identifier object_property_set_type1 =~ "^object_property_set_.*"; +identifier object_property_set_type2 =~ "^object_property_set_.*"; +expression obj; +@@ +void func(..., Error **errp) +{ + <+... + object_property_set_type1(obj, ..., &err); + ... when != err + object_property_set_type2(obj, ..., &err); + ...+> +} + +@@ +Error *match.err; +identifier match.errp; +identifier match.object_property_set_type1; +expression match.obj; +@@ + object_property_set_type1(obj, ..., &err); ++if (err) { ++ error_propagate(errp, err); ++ return; ++} + +@manual depends on never match@ +Error *err; +identifier object_property_set_type1 =~ "^object_property_set_.*"; +identifier object_property_set_type2 =~ "^object_property_set_.*"; +position p; +@@ + object_property_set_type1@p(..., &err); + ... when != err + object_property_set_type2(..., &err); + +@script:python@ +f << manual.object_property_set_type1; +p << manual.p; +@@ +print("[[manual check required: " + "error_propagate() might be missing in {}() {}:{}:{}]]".format( + f, p[0].file, p[0].line, p[0].column)) -- 2.21.1