Re: [PATCH] sched/core: Combine separate 'else' and 'if' statements
From: Valentin Schneider
Date: Fri May 15 2026 - 13:33:03 EST
On 13/05/26 16:54, luoliang@xxxxxxxxxx wrote:
> From: Liang Luo <luoliang@xxxxxxxxxx>
>
> The kernel coding style recommends using 'else if' instead of
> placing 'if' on a separate line after 'else'. This change makes
> the code consistent with the rest of the kernel codebase.
>
> Signed-off-by: Liang Luo <luoliang@xxxxxxxxxx>
Reviewed-by: Valentin Schneider <vschneid@xxxxxxxxxx>
Seems to be the only one in kernel/, a quick coccinelle script tells me
there's:
kernel/events/core.c:12160:3-7: ERROR: else (line 12160) and if (line 12162) should be on same line as 'else if'
kernel/sched/core.c:3727:1-5: ERROR: else (line 3727) and if (line 3728) should be on same line as 'else if'
kernel/seccomp.c:734:3-7: ERROR: else (line 734) and if (line 736) should be on same line as 'else if'
but the two other ones are legit uses (#ifdef faffery).
A quick look at the whole tree suggests there may be a few other places to
fix. Anywho, if you want to play around:
---
// SPDX-License-Identifier: GPL-2.0-only
/// Detect separate 'else' and 'if' that should be combined as 'else if'
///
// Confidence: High
// Copyright: (C) 2026 Valentin Schneider, Red Hat
// Comments:
// Options: --no-includes --include-headers
virtual report
@r depends on report@
expression E1, E2;
position p1, p2;
@@
if (E1) {
...
}
else@p1
if@p2 (E2) {
...
}
@script:python@
p1 << r.p1;
p2 << r.p2;
@@
if p1[0].line != p2[0].line:
msg = "WARNING: split 'else if' at lines %s & %s" % (p1[0].line, p2[0].line)
coccilib.report.print_report(p1[0], msg)