[tip: timers/vdso] timens: Use task_lock guard in timens_get*()

tip-bot2 for Thomas Weißschuh posted 1 patch 3 hours ago
kernel/time/namespace.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
[tip: timers/vdso] timens: Use task_lock guard in timens_get*()
Posted by tip-bot2 for Thomas Weißschuh 3 hours ago
The following commit has been merged into the timers/vdso branch of tip:

Commit-ID:     7138a8698a39e81eb153e05500823fff76d5b3bd
Gitweb:        https://git.kernel.org/tip/7138a8698a39e81eb153e05500823fff76d5b3bd
Author:        Thomas Weißschuh <thomas.weissschuh@linutronix.de>
AuthorDate:    Mon, 30 Mar 2026 09:07:58 +02:00
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Wed, 01 Apr 2026 17:13:36 +02:00

timens: Use task_lock guard in timens_get*()

Simplify the logic in timens_get*() by converting the task_lock
usage to a guard().

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260330-timens-cleanup-v1-4-936e91c9dd30@linutronix.de
---
 kernel/time/namespace.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index 084ceec..4bca3f7 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -154,34 +154,32 @@ void free_time_ns(struct time_namespace *ns)
 
 static struct ns_common *timens_get(struct task_struct *task)
 {
-	struct time_namespace *ns = NULL;
+	struct time_namespace *ns;
 	struct nsproxy *nsproxy;
 
-	task_lock(task);
+	guard(task_lock)(task);
 	nsproxy = task->nsproxy;
-	if (nsproxy) {
-		ns = nsproxy->time_ns;
-		get_time_ns(ns);
-	}
-	task_unlock(task);
+	if (!nsproxy)
+		return NULL;
 
-	return ns ? &ns->ns : NULL;
+	ns = nsproxy->time_ns;
+	get_time_ns(ns);
+	return &ns->ns;
 }
 
 static struct ns_common *timens_for_children_get(struct task_struct *task)
 {
-	struct time_namespace *ns = NULL;
+	struct time_namespace *ns;
 	struct nsproxy *nsproxy;
 
-	task_lock(task);
+	guard(task_lock)(task);
 	nsproxy = task->nsproxy;
-	if (nsproxy) {
-		ns = nsproxy->time_ns_for_children;
-		get_time_ns(ns);
-	}
-	task_unlock(task);
+	if (!nsproxy)
+		return NULL;
 
-	return ns ? &ns->ns : NULL;
+	ns = nsproxy->time_ns_for_children;
+	get_time_ns(ns);
+	return &ns->ns;
 }
 
 static void timens_put(struct ns_common *ns)