Skip to contentSkip to conversation

checkpatch: Detect newlines in error_report and other error functions

PATCH Superseded Jason J. Herne 1 participant 2 messages Dec 11, 2015 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: Detect newlines in error_report and other error functions

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 does not catch the newline when it is in a multiline statement. This is quite a bit more difficult and can be handled as follow on work.

---
 scripts/checkpatch.pl | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
scripts/checkpatch.pl +16 -0
index b0f6e11..476ac13 100755
@@ -2511,6 +2511,22 @@ sub process {
 			WARN("use QEMU instead of Qemu or QEmu\n" . $herecurr);
 		}
 
+# Qemu error function tests
+# FIXME: This does not work for multiline statements
+	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);
+	}
+
 # check for non-portable ffs() calls that have portable alternatives in QEMU
 		if ($line =~ /\bffs\(/) {
 			ERROR("use ctz32() instead of ffs()\n" . $herecurr);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 8 lines · 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 does not catch the newline when it is in a multiline statement. This is quite a bit more difficult and can be handled as follow on work.

...

Ignore this one, I found some time to write up a better version that handles the most common multi-line cases. See v2. Sorry for the spam :)

Signature · 1 line
-- Jason J. Herne ([email protected])