Skip to contentSkip to conversation

__kill_pgrp_info: simplify the calculation of return value

PATCH RESEND Applied Oleg Nesterov 1 participant 1 message Aug 23, 2023

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 __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.

---
 kernel/signal.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
kernel/signal.c +11 -6
index 128e9bb3d1a2..c0acdfd4c81b 100644
@@ -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)
Signature · 1 line
2.25.1.362.g51ebf55