Calls passing &error_abort or &error_fatal don't return. Any code after such use is dubious. Add a coccinelle patch to detect such pattern.
Inspired-by: Kevin Wolf <kw...@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <phi...@redhat.com> --- .../use-after-abort-fatal-errp.cocci | 33 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 34 insertions(+) create mode 100644 scripts/coccinelle/use-after-abort-fatal-errp.cocci diff --git a/scripts/coccinelle/use-after-abort-fatal-errp.cocci b/scripts/coccinelle/use-after-abort-fatal-errp.cocci new file mode 100644 index 00000000000..ead9de5826a --- /dev/null +++ b/scripts/coccinelle/use-after-abort-fatal-errp.cocci @@ -0,0 +1,33 @@ +/* Find dubious code use after error_abort/error_fatal + * + * Inspired by this patch: + * https://www.mail-archive.com/qemu-devel@nongnu.org/msg789501.html + * + * Copyright (C) 2121 Red Hat, Inc. + * + * Authors: + * Philippe Mathieu-Daudé + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +@@ +identifier func_with_errp; +@@ +( + if (func_with_errp(..., &error_fatal)) { + /* Used for displaying help message */ + ... + exit(...); + } +| +*if (func_with_errp(..., &error_fatal)) { + /* dubious code */ + ... + } +| +*if (func_with_errp(..., &error_abort)) { + /* dubious code */ + ... + } +) diff --git a/MAINTAINERS b/MAINTAINERS index 1e15dab8cd4..db6596eb06d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2368,6 +2368,7 @@ F: scripts/coccinelle/error_propagate_null.cocci F: scripts/coccinelle/remove_local_err.cocci F: scripts/coccinelle/use-error_fatal.cocci F: scripts/coccinelle/errp-guard.cocci +F: scripts/coccinelle/use-after-abort-fatal-errp.cocci GDB stub M: Alex Bennée <alex.ben...@linaro.org> -- 2.26.2