The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Bradley Morgan <bradley.morgan@linux.dev>
To: Oleg Nesterov <oleg@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Christian Brauner <brauner@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>,
	Andrea Calabrese <andrea.calabrese@amarulasolutions.com>,
	linux-kernel@vger.kernel.org,
	Bradley Morgan <bradley.morgan@linux.dev>
Subject: [PATCH] signal: simplify next_signal()
Date: Tue,  1 Dec 2026 20:31:45 +0000	[thread overview]
Message-ID: <20261201203145.299191-1-bradley.morgan@linux.dev> (raw)

Well, next_signal() has a switch over _NSIG_WORDS that special cases
the 1 and 2 word signal sets, but the generic loop already handles
both of them. The 2 word case is just the first iteration, and for 1
word the loop never runs at all, so none of that is needed.

_NSIG_WORDS is a compile time constant, so the compiler unrolls the
loop anyway and the switch is just duplicate code. Same thing commit
b7a8d7589a632 ("kernel: refactor: shorten has_pending_signals")
removed.

Signed-off-by: Bradley Morgan <bradley.morgan@linux.dev>
---
 kernel/signal.c | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index dd770e68faee0..c119411aa9ed3 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -184,7 +184,7 @@ void calculate_sigpending(void)
 
 int next_signal(struct sigpending *pending, sigset_t *mask)
 {
-	unsigned long i, *s, *m, x;
+	unsigned long *s, *m, x;
 	int sig = 0;
 
 	s = pending->signal.sig;
@@ -194,7 +194,7 @@ int next_signal(struct sigpending *pending, sigset_t *mask)
 	 * Handle the first word specially: it contains the
 	 * synchronous signals that need to be dequeued first.
 	 */
-	x = *s &~ *m;
+	x = *s & ~*m;
 	if (x) {
 		if (x & SYNCHRONOUS_MASK)
 			x &= SYNCHRONOUS_MASK;
@@ -202,26 +202,11 @@ int next_signal(struct sigpending *pending, sigset_t *mask)
 		return sig;
 	}
 
-	switch (_NSIG_WORDS) {
-	default:
-		for (i = 1; i < _NSIG_WORDS; ++i) {
-			x = *++s &~ *++m;
-			if (!x)
-				continue;
-			sig = ffz(~x) + i*_NSIG_BPW + 1;
-			break;
-		}
-		break;
-
-	case 2:
-		x = s[1] &~ m[1];
+	for (unsigned long i = 1; i < _NSIG_WORDS; i++) {
+		x = s[i] & ~m[i];
 		if (!x)
-			break;
-		sig = ffz(~x) + _NSIG_BPW + 1;
-		break;
-
-	case 1:
-		/* Nothing to do */
+			continue;
+		sig = ffz(~x) + i * _NSIG_BPW + 1;
 		break;
 	}
 

                 reply	other threads:[~2026-12-01 20:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201203145.299191-1-bradley.morgan@linux.dev \
    --to=bradley.morgan@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=andrea.calabrese@amarulasolutions.com \
    --cc=brauner@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=tglx@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox