checkpatch.pl: Add warning for harmful goto labels
PATCH 1/1 checkpatch.pl: Add warning for harmful goto labels
Issue a warning for too broad goto labels that may make the code to follow the wrong exit path, thus causing hard to debug bugs.
--- scripts/checkpatch.pl | 13 +++++++++++++ 1 file changed, 13 insertions(+)
scripts/checkpatch.pl +13 -0
@@ -444,6 +444,11 @@ our $allowed_asm_includes = qr{(?x: )}; # memory.h: ARM has a custom one +our @goto_harmful_labels = qw( + out + fail + ); + # Load common spelling mistakes and build regular expression list. my $misspellings; my %spelling_fix;
@@ -2702,6 +2707,14 @@ sub process { } } + if ($sline =~ /goto (.*);/) { + my $label = $1; + if (grep { /^$label$/ } @goto_harmful_labels) { + WARN("HARMFUL_GOTO_LABEL", + "Goto label '$label' is considered harmful\n" . $herecurr); + } + } + # discourage the addition of CONFIG_EXPERIMENTAL in #if(def). if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_EXPERIMENTAL\b/) { WARN("CONFIG_EXPERIMENTAL",
Signature · 1 line
2.1.4
Quoted 25 lines · L. Alberto Giménez
Issue a warning for too broad goto labels that may make the code to follow the wrong exit path, thus causing hard to debug bugs.
Signed-off-by L. Alberto Giménez <[email protected]>--- scripts/checkpatch.pl | 13 +++++++++++++ 1 file changed, 13 insertions(+)scripts/checkpatch.pl +5
-0@@ -444,6 +444,11 @@ our $allowed_asm_includes = qr{(?x: )}; # memory.h: ARM has a custom one +our @goto_harmful_labels = qw( + out + fail + ); + # Load common spelling mistakes and build regular expression list. my $misspellings; my %spelling_fix;
scripts/checkpatch.pl sub process { · line 2714
Quoted 8 lines
scripts/checkpatch.pl +5
-0@@ -2702,6 +2707,14 @@ sub process { } } + if ($sline =~ /goto (.*);/) { + my $label = $1; + if (grep { /^$label$/ } @goto_harmful_labels) { + WARN("HARMFUL_GOTO_LABEL", + "Goto label '$label' is considered harmful\n" . $herecurr);
Huh? Since when?
rw@azrael:~/linux (for-v4.1/uml_misc $)> git grep -e "goto out;" | wc -l 26667
rw@azrael:~/linux (for-v4.1/uml_misc $)> git grep -e "goto fail;" | wc -l 3733
What is next? Variable name "i" considered harmful? Can we please stop this nonsense.
Signature · 2 lines
Thanks, //richard
Quoted 1 line · Richard Weinberger
Huh? Since when?
There are a lot of cases where a too generic goto label for cleanup causes a bug or makes debugging harder.
Last time was this G+ post, by Dan Carpenter:
https://plus.google.com/106378716002406849458/posts/DfuAkt8szf2
Quoted 4 lines
rw@azrael:~/linux (for-v4.1/uml_misc $)> git grep -e "goto out;" | wc -l 26667
rw@azrael:~/linux (for-v4.1/uml_misc $)> git grep -e "goto fail;" | wc -l 3733
If something is already in the kernel code, does that mean that it's OK? I honestly don't think so, and I think that goto labels for cleanup exit paths should be a little more descriptive.
Quoted 1 line
What is next? Variable name "i" considered harmful?
No one complained about that so far. I might add that to checkpatch.pl if needed.
Quoted 1 line
Can we please stop this nonsense.
It's just a proposal for a warning. If it is really not needed, it won't be applied and life will go on :)
Signature · 2 lines
L. Alberto Giménez GnuPG key ID 0xDD4E27AB
Am 21.03.2015 um 23:06 schrieb L. Alberto Giménez:
Quoted 11 lines · Richard Weinberger
Quoted 1 line
Huh? Since when?
There are a lot of cases where a too generic goto label for cleanup causes a bug or makes debugging harder.
Last time was this G+ post, by Dan Carpenter:
https://plus.google.com/106378716002406849458/posts/DfuAkt8szf2
Quoted 8 lines
Quoted 4 lines
rw@azrael:~/linux (for-v4.1/uml_misc $)> git grep -e "goto out;" | wc -l 26667
rw@azrael:~/linux (for-v4.1/uml_misc $)> git grep -e "goto fail;" | wc -l 3733If something is already in the kernel code, does that mean that it's OK? I honestly don't think so, and I think that goto labels for cleanup exit paths should be a little more descriptive.
I disagree. out and exit are perfectly fine labels.
Quoted 4 lines
Quoted 1 line
What is next? Variable name "i" considered harmful?
No one complained about that so far. I might add that to checkpatch.pl if needed.
I *really* *really* hope you're kidding.
Quoted 4 lines
Quoted 1 line
Can we please stop this nonsense.
It's just a proposal for a warning. If it is really not needed, it won't be applied and life will go on :)
checkpatch.pl is already more than annoying. It used to be a nice tool but it becomes more and more an harassment for guys who actually work on the kernel.
Thanks,
//richard
Joe Perches
maintainerQuoted 3 lines · Richard Weinberger
Am 21.03.2015 um 23:06 schrieb L. Alberto Giménez:
Quoted 2 lines
There are a lot of cases where a too generic goto label for cleanup causes a bug or makes debugging harder.
[]
Quoted 5 lines
Quoted 3 lines
If something is already in the kernel code, does that mean that it's OK? I honestly don't think so, and I think that goto labels for cleanup exit paths should be a little more descriptive.
I disagree. out and exit are perfectly fine labels.
I agree with you Richard.
While the form of the patch is fine, but content is not.
There might be a case for a coccinelle style patch that looks for more than a single label in a function and looks at the label name choices, but I think it'd be pretty dubious at best.
Quoted 2 lines
Quoted 2 lines
It's just a proposal for a warning. If it is really not needed, it won't be applied and life will go on :)
In that case, it'd be nicer to preface the patch subject with RFC
Quoted 2 lines
checkpatch.pl is already more than annoying. It used to be a nice tool but it becomes more and more an harassment for guys who actually work on the kernel.
Richard, what sub-optimal messages do you think checkpatch produces by default?
cheers, Joe
Quoted 9 lines · Joe Perches
[]
Quoted 5 lines
Quoted 3 lines
If something is already in the kernel code, does that mean that it's OK? I honestly don't think so, and I think that goto labels for cleanup exit paths should be a little more descriptive.
I disagree. out and exit are perfectly fine labels.
I agree with you Richard.
[...]
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
It's just a proposal for a warning. If it is really not needed, it won't be applied and life will go on :)
In that case, it'd be nicer to preface the patch subject with RFC
Yes, you are right, sorry about that.
Thank you for the feedback guys!
And Richard, of course I was kidding about the 'i' variable. I enjoy sarcasm myself too :)
Best regards,
Signature · 2 lines
L. Alberto Giménez GnuPG key ID 0xDD4E27AB
Hi Alberto,
Quoted 2 lines · L. Alberto Giménez
Issue a warning for too broad goto labels that may make the code to follow the wrong exit path, thus causing hard to debug bugs.
What compiler allowed duplicate goto labels?
Regards,
Peter Hurley
Quoted 7 lines · Peter Hurley
Hi Alberto,
Quoted 2 lines · L. Alberto Giménez
Issue a warning for too broad goto labels that may make the code to follow the wrong exit path, thus causing hard to debug bugs.
What compiler allowed duplicate goto labels?
Humans are bad at following code paths, and making modifications to such code may lead to errors if the code is not descriptive enough, please check my reply to Richard for an explanation.
Regards,
Signature · 2 lines
L. Alberto Giménez GnuPG key ID 0xDD4E27AB