]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
timens: Use mutex guard in proc_timens_set_offset()
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>
Mon, 30 Mar 2026 07:07:57 +0000 (09:07 +0200)
committerThomas Gleixner <tglx@kernel.org>
Wed, 1 Apr 2026 15:13:35 +0000 (17:13 +0200)
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

index 37495bde92a40f33b1abf7839bab15e56d0f5432..084ceec3549593baea28ce3065b46a13fe35c9c9 100644 (file)
@@ -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 = {