From: Oleg Nesterov <oleg@redhat.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: David Laight <David.Laight@ACULAB.COM>,
Petr Skocik <pskocik@gmail.com>,
Kees Cook <keescook@chromium.org>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Marco Elver <elver@google.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] __kill_pgrp_info: simplify the calculation of return value
Date: Thu, 17 Aug 2023 17:47:43 +0200 [thread overview]
Message-ID: <20230817154743.GA18674@redhat.com> (raw)
In-Reply-To: <871qg28esu.fsf@email.froward.int.ebiederm.org>
On 08/16, Eric W. Biederman wrote:
>
> > We should be consistent and ensure __kill_pgrp_info uses
> > the same code pattern, otherwise it will be difficult to
> > see they use the same logic.
Hmm, agreed.
Then I think we should change __kill_pgrp_info() first, then "copy"
this pattern into kill_something_info() in a separate patch.
> > I think for both patterns the reader of the code is going to have to
> > stop and think about what is going on to understand the logic.
Yes, although to me the current code looks less clear but this is subjective.
But I agree this needs a comment. How about the patch below?
From 753d4edd1f2f21f9f9181b9ff7394ed098d58ff6 Mon Sep 17 00:00:00 2001
From: Oleg Nesterov <oleg@redhat.com>
Date: Thu, 17 Aug 2023 17:38:55 +0200
Subject: [PATCH] __kill_pgrp_info: simplify the calculation of return value
No need to calculate/check the "success" variable, we can kill it and update
retval in the main loop unless it is zero.
Suggested-by: David Laight <David.Laight@ACULAB.COM>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/signal.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index 128e9bb3d1a2..c0acdfd4c81b 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1460,16 +1460,21 @@ int group_send_sig_info(int sig, struct kernel_siginfo *info,
int __kill_pgrp_info(int sig, struct kernel_siginfo *info, struct pid *pgrp)
{
struct task_struct *p = NULL;
- int retval, success;
+ int ret = -ESRCH;
- success = 0;
- retval = -ESRCH;
do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
int err = group_send_sig_info(sig, info, p, PIDTYPE_PGID);
- success |= !err;
- retval = err;
+ /*
+ * If group_send_sig_info() succeeds at least once ret
+ * becomes 0 and after that the code below has no effect.
+ * Otherwise we return the last err or -ESRCH if this
+ * process group is empty.
+ */
+ if (ret)
+ ret = err;
} while_each_pid_task(pgrp, PIDTYPE_PGID, p);
- return success ? 0 : retval;
+
+ return ret;
}
int kill_pid_info(int sig, struct kernel_siginfo *info, struct pid *pid)
--
2.25.1.362.g51ebf55
next prev parent reply other threads:[~2023-08-17 15:50 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 16:12 [PATCH 0/1] *** Fix kill(-1,s) returning 0 on 0 kills *** Petr Skocik
2022-11-22 16:12 ` [PATCH 1/1] Fix kill(-1,s) returning 0 on 0 kills Petr Skocik
2022-11-23 10:30 ` Oleg Nesterov
2022-11-23 11:20 ` Oleg Nesterov
2022-11-23 11:27 ` Petr Skocik
2022-11-23 11:56 ` Oleg Nesterov
2022-11-22 17:15 ` [PATCH 0/1] *** Fix kill(-1,s) returning 0 on 0 kills *** Kees Cook
2022-11-22 23:01 ` Petr Skocik
2023-08-09 12:27 ` Petr Skocik
2023-08-10 16:16 ` Eric W. Biederman
2023-08-10 21:30 ` Petr Skocik
2023-08-11 21:25 ` Eric W. Biederman
2023-08-11 22:16 ` [PATCH] signal: Fix the error return of kill -1 Eric W. Biederman
2023-08-14 14:06 ` Oleg Nesterov
2023-08-14 15:43 ` Oleg Nesterov
2023-08-15 14:47 ` David Laight
2023-08-15 15:11 ` Oleg Nesterov
2023-08-16 20:32 ` Eric W. Biederman
2023-08-16 21:06 ` Oleg Nesterov
2023-08-17 2:33 ` Eric W. Biederman
2023-08-17 4:37 ` Eric W. Biederman
2023-08-17 15:47 ` Oleg Nesterov [this message]
2023-08-11 23:37 ` [PATCH 0/1] *** Fix kill(-1,s) returning 0 on 0 kills *** Petr Skocik
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=20230817154743.GA18674@redhat.com \
--to=oleg@redhat.com \
--cc=David.Laight@ACULAB.COM \
--cc=ebiederm@xmission.com \
--cc=elver@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=pskocik@gmail.com \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.