Re: [PATCH 00/13] [RFC] Rust support

From: Greg Kroah-Hartman
Date: Fri Jul 29 2022 - 04:05:04 EST


On Thu, Jul 28, 2022 at 10:45:08PM +0200, Olliver Schinagl wrote:
> Hey Greg,
>
> On 28-07-2022 14:09, Greg Kroah-Hartman wrote:
> > On Thu, Jul 28, 2022 at 11:21:14AM +0100, Gary Guo wrote:
> > > Rust requires braces around branches of if expression, and C doesn't.
> > > So in kernel coding style you often have:
> > >
> > > if (condition) do_something();
> >
> > That is not a valid kernel coding style, and our tools should catch this
> > and prevent it from being added to the kernel tree.
> Are you sure? I'm not sure if this isn't true today, but I've certainly seen
> old code where this definitely was done. Was all of this cleaned up in the
> last 2+ years?

Given that I wrote about this back in 2002, and it was true then:
https://www.linuxjournal.com/article/5780
and:
https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.2.8887&rep=rep1&type=pdf

that is not anything new at all.

Yes, old code still survives that might not be correct, and some
subsystems might have added code over time without the proper style, but
our tools check that the above is not correct, you can check it
yourself:

$ cat foo.c
// SPDX-License-Identifier: GPL-2.0
int foo(int baz)
{
if (baz == 1) do_something();
}

$ ./scripts/checkpatch.pl --file --terse foo.c
foo.c:4: ERROR: trailing statements should be on next line
total: 1 errors, 0 warnings, 6 lines checked

thanks,

greg k-h