Re: latest checkpatch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 18, 2007 at 01:13:52PM +0200, Ingo Molnar wrote:
> 
> latest checkpatch.pl works really well on sched.c.
> 
> there's only one problem left, this bogus false positive warning 
> reappeared:
> 
>   WARNING: braces {} are not necessary for single statement blocks
>   #5710: FILE: sched.c:5710:
>   +       if (parent->groups == parent->groups->next) {
>   +               pflags &= ~(SD_LOAD_BALANCE |
>   +                               SD_BALANCE_NEWIDLE |
>   +                               SD_BALANCE_FORK |
>   +                               SD_BALANCE_EXEC |
>   +                               SD_SHARE_CPUPOWER |
>   +                               SD_SHARE_PKG_RESOURCES);
>   +       }
> 
> (there's another place in sched.c that trips this up too.)

It actually never went away, some of the wronger reports went away such
as counting a commented statement as a single statement.  The check for
length didn't make the cut for 0.11, as I was still thinking about
whether we wanted a subjective check on statements over and above the
"real" check for lines.

> i think it has been pointed out numerous times that it is perfectly fine 
> to use curly braces for multi-line single-statement blocks. That 
> includes simple cases like this too:
> 
> 	if (x) {
> 		/* do y() */
> 		y();
> 	}

Yes and the comment in there actually counts as a statement for counting
statement purposes.  

The plan is to move to counting lines and only winge on exactly one
line.  I have half a mind to make a subjective check on statements and a
full check on lines.  But probabally it will just move to lines.

> it's perfectly legitimate, in fact more robust. So if checkpatch.pl 
> wants to make any noise about such constructs it should warn about the 
> _lack_ of curly braces in every multi-line condition block _except_ the 
> only safe single-line statement:
> 
> 	if (x)
> 		y();

Indeed.  We should probabally do more on the indentation checks in
general.  The current direct check for:

	if (foo);
		bar();

Could probabally be generalised to look for this kind of error:

	if (foo)
		bar();
		baz();
	one();

-apw
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux