Commit 3fa3aeb4 authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Thomas Gleixner
Browse files

timens: Simplify some calls to put_time_ns()



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

Signed-off-by: default avatarThomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: default avatarThomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260330-timens-cleanup-v1-2-936e91c9dd30@linutronix.de
parent c2de5a5b
Loading
Loading
Loading
Loading
+11 −18
Original line number Diff line number Diff line
@@ -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;
}