mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/core: Combine separate 'else' and 'if' statements
@ 2026-06-08  7:18 luoliang
  2026-06-08  8:08 ` Peter Zijlstra
  2026-06-09  8:32 ` [tip: sched/core] " tip-bot2 for Liang Luo
  0 siblings, 2 replies; 5+ messages in thread
From: luoliang @ 2026-06-08  7:18 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra
  Cc: Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
	linux-kernel, Liang Luo

From: Liang Luo <luoliang@kylinos.cn>

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@kylinos.cn>
---
 kernel/sched/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index da20fb6ea25a..c2bf0fc6ac97 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3716,8 +3716,7 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
 		en_flags |= ENQUEUE_RQ_SELECTED;
 	if (wake_flags & WF_MIGRATED)
 		en_flags |= ENQUEUE_MIGRATED;
-	else
-	if (p->in_iowait) {
+	else if (p->in_iowait) {
 		delayacct_blkio_end(p);
 		atomic_dec(&task_rq(p)->nr_iowait);
 	}
--
2.45.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sched/core: Combine separate 'else' and 'if' statements
  2026-06-08  7:18 [PATCH] sched/core: Combine separate 'else' and 'if' statements luoliang
@ 2026-06-08  8:08 ` Peter Zijlstra
  2026-06-09  8:32 ` [tip: sched/core] " tip-bot2 for Liang Luo
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2026-06-08  8:08 UTC (permalink / raw)
  To: luoliang
  Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak, linux-kernel

On Mon, Jun 08, 2026 at 03:18:42PM +0800, luoliang@kylinos.cn wrote:
> From: Liang Luo <luoliang@kylinos.cn>
> 
> 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.

Right, this is because the things used to be inside #ifdef CONFIG_SMP.

I did notice it a few times, but I generally don't bother with
trivialities like this until the code needs touching for other reasons.

But I suppose since you took the effort, I might as well apply this. But
please don't go whitespace fixing the scheduler code.

> Signed-off-by: Liang Luo <luoliang@kylinos.cn>
> ---
>  kernel/sched/core.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index da20fb6ea25a..c2bf0fc6ac97 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3716,8 +3716,7 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
>  		en_flags |= ENQUEUE_RQ_SELECTED;
>  	if (wake_flags & WF_MIGRATED)
>  		en_flags |= ENQUEUE_MIGRATED;
> -	else
> -	if (p->in_iowait) {
> +	else if (p->in_iowait) {
>  		delayacct_blkio_end(p);
>  		atomic_dec(&task_rq(p)->nr_iowait);
>  	}
> --
> 2.45.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip: sched/core] sched/core: Combine separate 'else' and 'if' statements
  2026-06-08  7:18 [PATCH] sched/core: Combine separate 'else' and 'if' statements luoliang
  2026-06-08  8:08 ` Peter Zijlstra
@ 2026-06-09  8:32 ` tip-bot2 for Liang Luo
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot2 for Liang Luo @ 2026-06-09  8:32 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Liang Luo, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     76124a050ddbc8b252172205ab04f10a83c03a4d
Gitweb:        https://git.kernel.org/tip/76124a050ddbc8b252172205ab04f10a83c03a4d
Author:        Liang Luo <luoliang@kylinos.cn>
AuthorDate:    Mon, 08 Jun 2026 15:18:42 +08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 09 Jun 2026 10:28:08 +02:00

sched/core: Combine separate 'else' and 'if' statements

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@kylinos.cn>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260608071842.325159-1-luoliang@kylinos.cn
---
 kernel/sched/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index e745c58..2f4530e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3816,8 +3816,7 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
 		en_flags |= ENQUEUE_RQ_SELECTED;
 	if (wake_flags & WF_MIGRATED)
 		en_flags |= ENQUEUE_MIGRATED;
-	else
-	if (p->in_iowait) {
+	else if (p->in_iowait) {
 		delayacct_blkio_end(p);
 		atomic_dec(&task_rq(p)->nr_iowait);
 	}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sched/core: Combine separate 'else' and 'if' statements
  2026-05-13  8:54 [PATCH] " luoliang
@ 2026-05-15 16:24 ` Valentin Schneider
  0 siblings, 0 replies; 5+ messages in thread
From: Valentin Schneider @ 2026-05-15 16:24 UTC (permalink / raw)
  To: luoliang, Ingo Molnar, Peter Zijlstra
  Cc: Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, K Prateek Nayak, linux-kernel, Liang Luo

On 13/05/26 16:54, luoliang@kylinos.cn wrote:
> From: Liang Luo <luoliang@kylinos.cn>
>
> 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@kylinos.cn>

Reviewed-by: Valentin Schneider <vschneid@redhat.com>


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)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] sched/core: Combine separate 'else' and 'if' statements
@ 2026-05-13  8:54 luoliang
  2026-05-15 16:24 ` Valentin Schneider
  0 siblings, 1 reply; 5+ messages in thread
From: luoliang @ 2026-05-13  8:54 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra
  Cc: Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
	linux-kernel, Liang Luo

From: Liang Luo <luoliang@kylinos.cn>

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@kylinos.cn>
---
 kernel/sched/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index da20fb6ea25a..c2bf0fc6ac97 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3716,8 +3716,7 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
 		en_flags |= ENQUEUE_RQ_SELECTED;
 	if (wake_flags & WF_MIGRATED)
 		en_flags |= ENQUEUE_MIGRATED;
-	else
-	if (p->in_iowait) {
+	else if (p->in_iowait) {
 		delayacct_blkio_end(p);
 		atomic_dec(&task_rq(p)->nr_iowait);
 	}
--
2.45.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-09  8:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-08  7:18 [PATCH] sched/core: Combine separate 'else' and 'if' statements luoliang
2026-06-08  8:08 ` Peter Zijlstra
2026-06-09  8:32 ` [tip: sched/core] " tip-bot2 for Liang Luo
  -- strict thread matches above, loose matches on Subject: below --
2026-05-13  8:54 [PATCH] " luoliang
2026-05-15 16:24 ` Valentin Schneider

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®