mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Thomas Weißschuh" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: thomas.weissschuh@linutronix.de,
	Thomas Gleixner <tglx@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: timers/vdso] timens: Simplify some calls to put_time_ns()
Date: Wed, 01 Apr 2026 15:16:20 -0000	[thread overview]
Message-ID: <177505658043.1647592.3870412071820971815.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260330-timens-cleanup-v1-2-936e91c9dd30@linutronix.de>

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;
 }

  reply	other threads:[~2026-04-01 15:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-bot2 for Thomas Weißschuh [this message]
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

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=177505658043.1647592.3870412071820971815.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=x86@kernel.org \
    /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 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®