qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>
Subject: [PATCH] scripts/coccinelle: Catch dubious code after &error_abort/&error_fatal
Date: Thu, 11 Mar 2021 20:27:00 +0100	[thread overview]
Message-ID: <20210311192700.1441263-1-philmd@redhat.com> (raw)

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 <kwolf@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@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.bennee@linaro.org>
-- 
2.26.2



             reply	other threads:[~2021-03-11 19:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 19:27 Philippe Mathieu-Daudé [this message]
2021-03-12  8:58 ` [PATCH] scripts/coccinelle: Catch dubious code after &error_abort/&error_fatal Markus Armbruster
2021-03-12  9:57   ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210311192700.1441263-1-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).