All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] checkpatch: Detect newlines in error_report and other error functions
@ 2015-12-11 18:30 Jason J. Herne
  2015-12-14 12:47 ` Markus Armbruster
  2016-01-11 21:37 ` Markus Armbruster
  0 siblings, 2 replies; 8+ messages in thread
From: Jason J. Herne @ 2015-12-11 18:30 UTC (permalink / raw)
  To: blauwirbel, cornelia.huck, qemu-devel; +Cc: Jason J. Herne

We don't want newlines embedded in error messages. This seems to be a common
problem with new code so let's try to catch it with checkpatch.

This will not catch cases where newlines are inserted into the middle of an
existing multi-line statement. But those cases should be rare.

Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
---
 scripts/checkpatch.pl | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b0f6e11..51ea667 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2511,6 +2511,45 @@ sub process {
 			WARN("use QEMU instead of Qemu or QEmu\n" . $herecurr);
 		}
 
+# Qemu error function tests
+
+	# Find newlines in error function text
+	my $qemu_error_funcs = qr{error_setg|
+				error_setg_errno|
+				error_setg_win32|
+				error_set|
+				error_vprintf|
+				error_printf|
+				error_printf_unless_qmp|
+				error_vreport|
+				error_report}x;
+
+	if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(\s*\".*\\n/) {
+		WARN("Error function text should not contain newlines\n" . $herecurr);
+	}
+
+	# Continue checking for error function text that contains newlines. This
+	# check handles cases where string literals are spread over multiple lines.
+	# Example:
+	# error_report("Error msg line #1"
+	#              "Error msg line #2\n");
+	my $quoted_newline_regex = qr{\+\s*\".*\\n.*\"};
+	my $continued_str_literal = qr{\+\s*\".*\"};
+
+	if ($rawline =~ /$quoted_newline_regex/) {
+		# Backtrack to first line that does not contain only a quoted literal
+		# and assume that it is the start of the statement.
+		my $i = $linenr - 2;
+
+		while (($i >= 0) & $rawlines[$i] =~ /$continued_str_literal/) {
+			$i--;
+		}
+
+		if ($rawlines[$i] =~ /\b(?:$qemu_error_funcs)\s*\(/) {
+			WARN("Error function text should not contain newlines\n" . $herecurr);
+		}
+	}
+
 # check for non-portable ffs() calls that have portable alternatives in QEMU
 		if ($line =~ /\bffs\(/) {
 			ERROR("use ctz32() instead of ffs()\n" . $herecurr);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-01-11 21:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-11 18:30 [Qemu-devel] [PATCH v2] checkpatch: Detect newlines in error_report and other error functions Jason J. Herne
2015-12-14 12:47 ` Markus Armbruster
2015-12-14 14:45   ` Jason J. Herne
2015-12-14 15:40     ` Markus Armbruster
2015-12-17 17:49       ` Jason J. Herne
2015-12-17 18:28         ` Markus Armbruster
2015-12-18 15:06           ` Markus Armbruster
2016-01-11 21:37 ` Markus Armbruster

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.