[PATCH 3/4] timens: Use mutex guard in proc_timens_set_offset()

From: Thomas Weißschuh

Date: Mon Mar 30 2026 - 03:15:43 EST


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

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
---
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