提交 c00df19a 编写于 作者: J Joe Perches 提交者: Linus Torvalds

checkpatch: warn on break after goto or return with same tab indentation

Using break; after a goto or return is unnecessary so emit a warning
when the break is at the same indent level.

So this emits a warning on:

	switch (foo) {
	case 1:
		goto err;
		break;
	}

but not on:

	switch (foo) {
	case 1:
		if (bar())
			goto err;
		break;
	}
Signed-off-by: NJoe Perches <joe@perches.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 13f1937e
......@@ -2450,6 +2450,16 @@ sub process {
}
}
# check indentation of a line with a break;
# if the previous line is a goto or return and is indented the same # of tabs
if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
my $tabs = $1;
if ($prevline =~ /^\+$tabs(?:goto|return)\b/) {
WARN("UNNECESSARY_BREAK",
"break is not useful after a goto or return\n" . $hereprev);
}
}
# discourage the addition of CONFIG_EXPERIMENTAL in #if(def).
if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_EXPERIMENTAL\b/) {
WARN("CONFIG_EXPERIMENTAL",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册