mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] timens: Simplify some resource management through cleanup.h helpers
@ 2026-03-30  7:07 Thomas Weißschuh
  2026-03-30  7:07 ` [PATCH 1/4] timens: Add a __free() wrapper for put_time_ns() Thomas Weißschuh
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2026-03-30  7:07 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner
  Cc: linux-kernel, Thomas Weißschuh

Based on tip/timers/vdso.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (4):
      timens: Add a __free() wrapper for put_time_ns()
      timens: Simplify some calls to put_time_ns()
      timens: Use mutex guard in proc_timens_set_offset()
      timens: Use task_lock guard in timens_get*()

 include/linux/time_namespace.h |  3 ++
 kernel/time/namespace.c        | 67 ++++++++++++++++--------------------------
 2 files changed, 29 insertions(+), 41 deletions(-)
---
base-commit: 8e936460de513407846993b8409bff5cebdf10bf
change-id: 20260325-timens-cleanup-4294bbffdfa3
prerequisite-change-id: 20250908-vdso-timens-decoupling-24c0eee0c6c4:v2
prerequisite-patch-id: 69020428722a28a11c698ef8439f266bbacf1a26
prerequisite-patch-id: df6df9340399a47bef2b29b5073c7603cbb1b3f3

Best regards,
--  
Thomas Weißschuh <thomas.weissschuh@linutronix.de>


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

* [PATCH 1/4] timens: Add a __free() wrapper for put_time_ns()
  2026-03-30  7:07 [PATCH 0/4] timens: Simplify some resource management through cleanup.h helpers Thomas Weißschuh
@ 2026-03-30  7:07 ` Thomas Weißschuh
  2026-04-01 15:16   ` [tip: timers/vdso] " tip-bot2 for Thomas Weißschuh
  2026-03-30  7:07 ` [PATCH 2/4] timens: Simplify some calls to put_time_ns() Thomas Weißschuh
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Thomas Weißschuh @ 2026-03-30  7:07 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner
  Cc: linux-kernel, Thomas Weißschuh

The wrapper will be used to simplify cleanups of 'struct time_namespace'.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 include/linux/time_namespace.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h
index c1de21a27c34..58bd9728df58 100644
--- a/include/linux/time_namespace.h
+++ b/include/linux/time_namespace.h
@@ -8,6 +8,7 @@
 #include <linux/ns_common.h>
 #include <linux/err.h>
 #include <linux/time64.h>
+#include <linux/cleanup.h>
 
 struct user_namespace;
 extern struct user_namespace init_user_ns;
@@ -171,4 +172,6 @@ static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma)
 }
 #endif /* CONFIG_TIME_NS_VDSO */
 
+DEFINE_FREE(time_ns, struct time_namespace *, if (_T) put_time_ns(_T))
+
 #endif /* _LINUX_TIMENS_H */

-- 
2.53.0


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

* [PATCH 2/4] timens: Simplify some calls to put_time_ns()
  2026-03-30  7:07 [PATCH 0/4] timens: Simplify some resource management through cleanup.h helpers Thomas Weißschuh
  2026-03-30  7:07 ` [PATCH 1/4] timens: Add a __free() wrapper for put_time_ns() Thomas Weißschuh
@ 2026-03-30  7:07 ` Thomas Weißschuh
  2026-04-01 15:16   ` [tip: timers/vdso] " tip-bot2 for Thomas Weißschuh
  2026-03-30  7:07 ` [PATCH 3/4] timens: Use mutex guard in proc_timens_set_offset() Thomas Weißschuh
  2026-03-30  7:07 ` [PATCH 4/4] timens: Use task_lock guard in timens_get*() Thomas Weißschuh
  3 siblings, 1 reply; 9+ messages in thread
From: Thomas Weißschuh @ 2026-03-30  7:07 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner
  Cc: linux-kernel, Thomas Weißschuh

Use the new __free() based cleanup helpers to simplify some functions.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 kernel/time/namespace.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index 42302cc3f3fb..ae9a3a5d53ab 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -18,6 +18,7 @@
 #include <linux/cred.h>
 #include <linux/err.h>
 #include <linux/mm.h>
+#include <linux/cleanup.h>
 
 #include "namespace_internal.h"
 
@@ -252,7 +253,7 @@ static void show_offset(struct seq_file *m, int clockid, struct timespec64 *ts)
 void proc_timens_show_offsets(struct task_struct *p, struct seq_file *m)
 {
 	struct ns_common *ns;
-	struct time_namespace *time_ns;
+	struct time_namespace *time_ns __free(time_ns) = NULL;
 
 	ns = timens_for_children_get(p);
 	if (!ns)
@@ -261,14 +262,13 @@ void proc_timens_show_offsets(struct task_struct *p, struct seq_file *m)
 
 	show_offset(m, CLOCK_MONOTONIC, &time_ns->offsets.monotonic);
 	show_offset(m, CLOCK_BOOTTIME, &time_ns->offsets.boottime);
-	put_time_ns(time_ns);
 }
 
 int proc_timens_set_offset(struct file *file, struct task_struct *p,
 			   struct proc_timens_offset *offsets, int noffsets)
 {
 	struct ns_common *ns;
-	struct time_namespace *time_ns;
+	struct time_namespace *time_ns __free(time_ns) = NULL;
 	struct timespec64 tp;
 	int i, err;
 
@@ -277,10 +277,8 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 		return -ESRCH;
 	time_ns = to_time_ns(ns);
 
-	if (!file_ns_capable(file, time_ns->user_ns, CAP_SYS_TIME)) {
-		put_time_ns(time_ns);
+	if (!file_ns_capable(file, time_ns->user_ns, CAP_SYS_TIME))
 		return -EPERM;
-	}
 
 	for (i = 0; i < noffsets; i++) {
 		struct proc_timens_offset *off = &offsets[i];
@@ -293,15 +291,12 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 			ktime_get_boottime_ts64(&tp);
 			break;
 		default:
-			err = -EINVAL;
-			goto out;
+			return -EINVAL;
 		}
 
-		err = -ERANGE;
-
 		if (off->val.tv_sec > KTIME_SEC_MAX ||
 		    off->val.tv_sec < -KTIME_SEC_MAX)
-			goto out;
+			return -ERANGE;
 
 		tp = timespec64_add(tp, off->val);
 		/*
@@ -309,7 +304,7 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 		 * still unreachable.
 		 */
 		if (tp.tv_sec < 0 || tp.tv_sec > KTIME_SEC_MAX / 2)
-			goto out;
+			return -ERANGE;
 	}
 
 	mutex_lock(&timens_offset_lock);
@@ -338,8 +333,6 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 
 out_unlock:
 	mutex_unlock(&timens_offset_lock);
-out:
-	put_time_ns(time_ns);
 
 	return err;
 }

-- 
2.53.0


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

* [PATCH 3/4] timens: Use mutex guard in proc_timens_set_offset()
  2026-03-30  7:07 [PATCH 0/4] timens: Simplify some resource management through cleanup.h helpers Thomas Weißschuh
  2026-03-30  7:07 ` [PATCH 1/4] timens: Add a __free() wrapper for put_time_ns() Thomas Weißschuh
  2026-03-30  7:07 ` [PATCH 2/4] timens: Simplify some calls to put_time_ns() Thomas Weißschuh
@ 2026-03-30  7:07 ` Thomas Weißschuh
  2026-04-01 15:16   ` [tip: timers/vdso] " tip-bot2 for Thomas Weißschuh
  2026-03-30  7:07 ` [PATCH 4/4] timens: Use task_lock guard in timens_get*() Thomas Weißschuh
  3 siblings, 1 reply; 9+ messages in thread
From: Thomas Weißschuh @ 2026-03-30  7:07 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner
  Cc: linux-kernel, Thomas Weißschuh

Simplify the logic in proc_timens_set_offset() by converting the mutex
usage to a guard().

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 kernel/time/namespace.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index ae9a3a5d53ab..fbf026e63104 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -270,7 +270,7 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 	struct ns_common *ns;
 	struct time_namespace *time_ns __free(time_ns) = NULL;
 	struct timespec64 tp;
-	int i, err;
+	int i;
 
 	ns = timens_for_children_get(p);
 	if (!ns)
@@ -307,13 +307,10 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 			return -ERANGE;
 	}
 
-	mutex_lock(&timens_offset_lock);
-	if (time_ns->frozen_offsets) {
-		err = -EACCES;
-		goto out_unlock;
-	}
+	guard(mutex)(&timens_offset_lock);
+	if (time_ns->frozen_offsets)
+		return -EACCES;
 
-	err = 0;
 	/* Don't report errors after this line */
 	for (i = 0; i < noffsets; i++) {
 		struct proc_timens_offset *off = &offsets[i];
@@ -331,10 +328,7 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 		*offset = off->val;
 	}
 
-out_unlock:
-	mutex_unlock(&timens_offset_lock);
-
-	return err;
+	return 0;
 }
 
 const struct proc_ns_operations timens_operations = {

-- 
2.53.0


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

* [PATCH 4/4] timens: Use task_lock guard in timens_get*()
  2026-03-30  7:07 [PATCH 0/4] timens: Simplify some resource management through cleanup.h helpers Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2026-03-30  7:07 ` [PATCH 3/4] timens: Use mutex guard in proc_timens_set_offset() Thomas Weißschuh
@ 2026-03-30  7:07 ` Thomas Weißschuh
  2026-04-01 15:16   ` [tip: timers/vdso] " tip-bot2 for Thomas Weißschuh
  3 siblings, 1 reply; 9+ messages in thread
From: Thomas Weißschuh @ 2026-03-30  7:07 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner
  Cc: linux-kernel, Thomas Weißschuh

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>
---
 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 fbf026e63104..9d2e4870a2c5 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)

-- 
2.53.0


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

* [tip: timers/vdso] timens: Use task_lock guard in timens_get*()
  2026-03-30  7:07 ` [PATCH 4/4] timens: Use task_lock guard in timens_get*() Thomas Weißschuh
@ 2026-04-01 15:16   ` tip-bot2 for Thomas Weißschuh
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2026-04-01 15:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel

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)

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

* [tip: timers/vdso] timens: Use mutex guard in proc_timens_set_offset()
  2026-03-30  7:07 ` [PATCH 3/4] timens: Use mutex guard in proc_timens_set_offset() Thomas Weißschuh
@ 2026-04-01 15:16   ` tip-bot2 for Thomas Weißschuh
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2026-04-01 15:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the timers/vdso branch of tip:

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

timens: Use mutex guard in proc_timens_set_offset()

Simplify the logic in proc_timens_set_offset() by converting the mutex
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-3-936e91c9dd30@linutronix.de
---
 kernel/time/namespace.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index 37495bd..084ceec 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -270,7 +270,7 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 	struct time_namespace *time_ns __free(time_ns) = NULL;
 	struct ns_common *ns = timens_for_children_get(p);
 	struct timespec64 tp;
-	int i, err;
+	int i;
 
 	if (!ns)
 		return -ESRCH;
@@ -307,13 +307,10 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 			return -ERANGE;
 	}
 
-	mutex_lock(&timens_offset_lock);
-	if (time_ns->frozen_offsets) {
-		err = -EACCES;
-		goto out_unlock;
-	}
+	guard(mutex)(&timens_offset_lock);
+	if (time_ns->frozen_offsets)
+		return -EACCES;
 
-	err = 0;
 	/* Don't report errors after this line */
 	for (i = 0; i < noffsets; i++) {
 		struct proc_timens_offset *off = &offsets[i];
@@ -331,10 +328,7 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 		*offset = off->val;
 	}
 
-out_unlock:
-	mutex_unlock(&timens_offset_lock);
-
-	return err;
+	return 0;
 }
 
 const struct proc_ns_operations timens_operations = {

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

* [tip: timers/vdso] timens: Simplify some calls to put_time_ns()
  2026-03-30  7:07 ` [PATCH 2/4] timens: Simplify some calls to put_time_ns() Thomas Weißschuh
@ 2026-04-01 15:16   ` tip-bot2 for Thomas Weißschuh
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2026-04-01 15:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the timers/vdso branch of tip:

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

timens: Simplify some calls to put_time_ns()

Use the new __free() based cleanup helpers to simplify some functions.

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-2-936e91c9dd30@linutronix.de
---
 kernel/time/namespace.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index 42302cc..37495bd 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -18,6 +18,7 @@
 #include <linux/cred.h>
 #include <linux/err.h>
 #include <linux/mm.h>
+#include <linux/cleanup.h>
 
 #include "namespace_internal.h"
 
@@ -251,36 +252,33 @@ static void show_offset(struct seq_file *m, int clockid, struct timespec64 *ts)
 
 void proc_timens_show_offsets(struct task_struct *p, struct seq_file *m)
 {
-	struct ns_common *ns;
-	struct time_namespace *time_ns;
+	struct time_namespace *time_ns __free(time_ns) = NULL;
+	struct ns_common *ns = timens_for_children_get(p);
 
-	ns = timens_for_children_get(p);
 	if (!ns)
 		return;
+
 	time_ns = to_time_ns(ns);
 
 	show_offset(m, CLOCK_MONOTONIC, &time_ns->offsets.monotonic);
 	show_offset(m, CLOCK_BOOTTIME, &time_ns->offsets.boottime);
-	put_time_ns(time_ns);
 }
 
 int proc_timens_set_offset(struct file *file, struct task_struct *p,
 			   struct proc_timens_offset *offsets, int noffsets)
 {
-	struct ns_common *ns;
-	struct time_namespace *time_ns;
+	struct time_namespace *time_ns __free(time_ns) = NULL;
+	struct ns_common *ns = timens_for_children_get(p);
 	struct timespec64 tp;
 	int i, err;
 
-	ns = timens_for_children_get(p);
 	if (!ns)
 		return -ESRCH;
+
 	time_ns = to_time_ns(ns);
 
-	if (!file_ns_capable(file, time_ns->user_ns, CAP_SYS_TIME)) {
-		put_time_ns(time_ns);
+	if (!file_ns_capable(file, time_ns->user_ns, CAP_SYS_TIME))
 		return -EPERM;
-	}
 
 	for (i = 0; i < noffsets; i++) {
 		struct proc_timens_offset *off = &offsets[i];
@@ -293,15 +291,12 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 			ktime_get_boottime_ts64(&tp);
 			break;
 		default:
-			err = -EINVAL;
-			goto out;
+			return -EINVAL;
 		}
 
-		err = -ERANGE;
-
 		if (off->val.tv_sec > KTIME_SEC_MAX ||
 		    off->val.tv_sec < -KTIME_SEC_MAX)
-			goto out;
+			return -ERANGE;
 
 		tp = timespec64_add(tp, off->val);
 		/*
@@ -309,7 +304,7 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 		 * still unreachable.
 		 */
 		if (tp.tv_sec < 0 || tp.tv_sec > KTIME_SEC_MAX / 2)
-			goto out;
+			return -ERANGE;
 	}
 
 	mutex_lock(&timens_offset_lock);
@@ -338,8 +333,6 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
 
 out_unlock:
 	mutex_unlock(&timens_offset_lock);
-out:
-	put_time_ns(time_ns);
 
 	return err;
 }

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

* [tip: timers/vdso] timens: Add a __free() wrapper for put_time_ns()
  2026-03-30  7:07 ` [PATCH 1/4] timens: Add a __free() wrapper for put_time_ns() Thomas Weißschuh
@ 2026-04-01 15:16   ` tip-bot2 for Thomas Weißschuh
  0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2026-04-01 15:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the timers/vdso branch of tip:

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

timens: Add a __free() wrapper for put_time_ns()

The wrapper will be used to simplify cleanups of 'struct time_namespace'.

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-1-936e91c9dd30@linutronix.de
---
 include/linux/time_namespace.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h
index c1de21a..58bd972 100644
--- a/include/linux/time_namespace.h
+++ b/include/linux/time_namespace.h
@@ -8,6 +8,7 @@
 #include <linux/ns_common.h>
 #include <linux/err.h>
 #include <linux/time64.h>
+#include <linux/cleanup.h>
 
 struct user_namespace;
 extern struct user_namespace init_user_ns;
@@ -171,4 +172,6 @@ static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma)
 }
 #endif /* CONFIG_TIME_NS_VDSO */
 
+DEFINE_FREE(time_ns, struct time_namespace *, if (_T) put_time_ns(_T))
+
 #endif /* _LINUX_TIMENS_H */

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

end of thread, other threads:[~2026-04-01 15:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-30  7:07 [PATCH 0/4] timens: Simplify some resource management through cleanup.h helpers Thomas Weißschuh
2026-03-30  7:07 ` [PATCH 1/4] timens: Add a __free() wrapper for put_time_ns() Thomas Weißschuh
2026-04-01 15:16   ` [tip: timers/vdso] " tip-bot2 for Thomas Weißschuh
2026-03-30  7:07 ` [PATCH 2/4] timens: Simplify some calls to put_time_ns() Thomas Weißschuh
2026-04-01 15:16   ` [tip: timers/vdso] " tip-bot2 for Thomas Weißschuh
2026-03-30  7:07 ` [PATCH 3/4] timens: Use mutex guard in proc_timens_set_offset() Thomas Weißschuh
2026-04-01 15:16   ` [tip: timers/vdso] " tip-bot2 for Thomas Weißschuh
2026-03-30  7:07 ` [PATCH 4/4] timens: Use task_lock guard in timens_get*() Thomas Weißschuh
2026-04-01 15:16   ` [tip: timers/vdso] " tip-bot2 for Thomas Weißschuh

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

all inboxes | Powered by JetHome®