mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
To: Anna-Maria Behnsen <anna-maria@linutronix.de>,
	 Frederic Weisbecker <frederic@kernel.org>,
	 Thomas Gleixner <tglx@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Subject: [PATCH 3/4] timens: Use mutex guard in proc_timens_set_offset()
Date: Mon, 30 Mar 2026 09:07:57 +0200	[thread overview]
Message-ID: <20260330-timens-cleanup-v1-3-936e91c9dd30@linutronix.de> (raw)
In-Reply-To: <20260330-timens-cleanup-v1-0-936e91c9dd30@linutronix.de>

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


  parent reply	other threads:[~2026-03-30  7:09 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: timers/vdso] " tip-bot2 for Thomas Weißschuh
2026-03-30  7:07 ` Thomas Weißschuh [this message]
2026-04-01 15:16   ` [tip: timers/vdso] timens: Use mutex guard in proc_timens_set_offset() 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=20260330-timens-cleanup-v1-3-936e91c9dd30@linutronix.de \
    --to=thomas.weissschuh@linutronix.de \
    --cc=anna-maria@linutronix.de \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@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®