public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipc/sem: Three function calls less in do_semtimedop()
@ 2019-07-06 12:28 Markus Elfring
  2019-07-06 20:13 ` Colin Ian King
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2019-07-06 12:28 UTC (permalink / raw)
  To: kernel-janitors, Andrew Morton, Arnd Bergmann, Davidlohr Bueso,
	Gustavo A. R. Silva, Manfred Spraul, Mathieu Malaterre
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 6 Jul 2019 14:16:24 +0200

Avoid three function calls by using ternary operators instead of
conditional statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 ipc/sem.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/ipc/sem.c b/ipc/sem.c
index 7da4504bcc7c..56ea549ac270 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -2122,27 +2122,18 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops,
 		int idx = array_index_nospec(sops->sem_num, sma->sem_nsems);
 		curr = &sma->sems[idx];

-		if (alter) {
-			if (sma->complex_count) {
-				list_add_tail(&queue.list,
-						&sma->pending_alter);
-			} else {
-
-				list_add_tail(&queue.list,
-						&curr->pending_alter);
-			}
-		} else {
-			list_add_tail(&queue.list, &curr->pending_const);
-		}
+		list_add_tail(&queue.list,
+			      alter
+			      ? (sma->complex_count
+				? &sma->pending_alter
+				: &curr->pending_alter)
+			      : &curr->pending_const);
 	} else {
 		if (!sma->complex_count)
 			merge_queues(sma);

-		if (alter)
-			list_add_tail(&queue.list, &sma->pending_alter);
-		else
-			list_add_tail(&queue.list, &sma->pending_const);
-
+		list_add_tail(&queue.list,
+			      alter ? &sma->pending_alter : &sma->pending_const);
 		sma->complex_count++;
 	}

--
2.22.0


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

end of thread, other threads:[~2019-07-07  7:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-06 12:28 [PATCH] ipc/sem: Three function calls less in do_semtimedop() Markus Elfring
2019-07-06 20:13 ` Colin Ian King
2019-07-06 20:50   ` Al Viro
2019-07-07  7:09   ` Markus Elfring

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