Re: [RFC PATCH] checkpatch.pl: Add warning on non #define continuation lines

From: Mike Frysinger
Date: Tue Feb 02 2010 - 12:06:51 EST


On Tue, Feb 2, 2010 at 08:49, John Kacur wrote:
> On Tue, Feb 2, 2010 at 1:55 PM, Joe Perches wrote:
>> On Tue, 2010-02-02 at 11:08 +0000, Mark Brown wrote:
>>> it'd be good to also check for just regular use of
>>> continuations in code other than macro definitions. ÂThese are just a
>>> style nit but if there's a script that filters out false positives from
>>> the macros that'd be handy...
>>
>>> Running "grep ' \\$' sound/soc/blackfin/*.[ch]" suggests that there's
>>> still some of the continuations I mentioned above in there (plus a lot
>>> of false positives from macros).
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 3257d3d..a174501 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -1234,6 +1234,7 @@ sub process {
>>
>> Â Â Â Â$realcnt = 0;
>> Â Â Â Â$linenr = 0;
>> + Â Â Â my $in_define = 0;
>> Â Â Â Âforeach my $line (@lines) {
>> Â Â Â Â Â Â Â Â$linenr++;
>>
>> @@ -1388,6 +1389,16 @@ sub process {
>> Â Â Â Â Â Â Â Â Â Â Â ÂWARN("adding a line without newline at end of file\n" . $herecurr);
>> Â Â Â Â Â Â Â Â}
>>
>> + Â Â Â Â Â Â Â if ($rawline =~ /\\$/) {
>> + Â Â Â Â Â Â Â Â Â if ($rawline =~ /\s*\#\s*define\s+/) {
>> + Â Â Â Â Â Â Â Â Â Â Â $in_define = 1;
>> + Â Â Â Â Â Â Â Â Â } elsif (!$in_define) {
>> + Â Â Â Â Â Â Â Â Â Â Â WARN("Continuations outside of macros should be avoided\n" . $herecurr);
>> + Â Â Â Â Â Â Â Â Â }
>> + Â Â Â Â Â Â Â } else {
>> + Â Â Â Â Â Â Â Â Â $in_define = 0;
>> + Â Â Â Â Â Â Â }
>> +
>> Â# Blackfin: use hi/lo macros
>> Â Â Â Â Â Â Â Âif ($realfile =~ m@arch/blackfin/.*\.S$@) {
>> Â Â Â Â Â Â Â Â Â Â Â Âif ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
>>
>>find ./ -name "*.[ch]" | xargs ./scripts/checkpatch.pl -f | grep -a3 Continuations
>
> Checkpatch is already kind of loud, so I'm not sure I like the idea -
> you even say yourself that it's just a style nit.
> But just in-case there are a lot of people who do like this, then you
> have to do some work to get rid of false positives. Try something like
> the following.
>
> 1. apply your patch.
> 2. run something like
> find ./ -name "*.[ch]" | xargs ./scripts/checkpatch.pl -f | grep -a3
> Continuations
>
> and then go through the results looking for false positives.
>
> One that I see right away, is with #if
> For example,
>
> #39: FILE: arch/arm/mach-lh7a40x/lcd-panel.h:39:
> +#if defined (MACH_LPD79520)\
>
> WARNING: Continuations outside of macros should be avoided
> #40: FILE: arch/arm/mach-lh7a40x/lcd-panel.h:40:
> + || defined (MACH_LPD79524)\

those examples are missing spaces before the \ ;)
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/