lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 15 Sep 2023 00:17:58 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Geert Uytterhoeven <geert@...ux-m68k.org>
Cc:     Bartosz Golaszewski <brgl@...ev.pl>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Linus Walleij <linus.walleij@...aro.org>,
        Andy Shevchenko <andy@...nel.org>,
        Mitchell Levy <levymitchell0@...il.com>
Subject: Re: guard coding style (was: Re: [PATCH v1 05/10] gpio: pca953x:
 Simplify code with cleanup helpers)

On Thu, Sep 14, 2023 at 09:47:07AM +0200, Geert Uytterhoeven wrote:

> > Only compound statements need curly braces in the kernel and it has
> > been like this forever. I don't really see a need to make it an
> > exception.

Kernel coding style is a little different from what C demands.
Specifically, kernel style demands { } for anything multi-line.

Specifically:

	for (;;) {
		/* a comment */
		foo();
	}

or

	for (;;) {
		foo(a, very, long,
		    arg, chain);
	}

do both warrant a pile of curlies in kernel style where C does not
demand it.

> > That being said - I don't think the coding style for guard has ever
> > been addressed yet, so maybe bring it up with Peter Zijlstra?
> 
> That's a good idea!
> 
> I see Peter always used curly braces (but he didn't have any
> single-statement blocks, except for one with an "if", and we do tend
> to use curly braces in "for"-statements containing a single "if", too),
> but he does put a space after the "scoped_guard", as is also
> shown in the template in include/linux/cleanup.h:
> 
>     scoped_guard (name, args...) { }:
> 

Right, per scope_guard being a for loop I added the extra space. Our
coding style does;

	if (cond) { }

	while (cond) { }

	for (;;) { }

etc.. so I too did:

	scoped_guard (name, args...) { }

> Then, "guard" does not get a space (but it is funny syntax
> anyway, with the double set of parentheses ;-).  The template in
> include/linux/cleanup.h doesn't match actual usage as it lacks the
> second set of parentheses:
> 
>     guard(name):
> 
> Peter: care to comment?
> Or do you have a different bikeshed to paint today? ;-)

For guard I read the first pair as if it were a C++ template, that is, I
pretend, it is actually written like:

	guard<name>(args..);

Both are 'odd' in numerous ways and inconsistent vs where the 'args...'
go, but alas, we're trying to wrangle this inside the constraints
imposed upon us by C and CPP our dear pre-processor.



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ