[PATCH 1/7] POSIX clock ID check function

Erez Geva
2020-10-01T21:03:01Z

Add function to check whether a clock ID refer to
a file descriptor of a POSIX dynamic clock.

Signed-off-by: Erez Geva <erez.geva.ext@siemens.com>
---
include/linux/posix-timers.h | 5 +++++
kernel/time/posix-timers.c | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 896c16d2c5fb..7cb551bbb763 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -57,6 +57,11 @@ static inline int clockid_to_fd(const clockid_t clk)
return ~(clk >> 3);
}

+static inline bool is_clockid_fd_clock(const clockid_t clk)
+{
+ return (clk < 0) && ((clk & CLOCKFD_MASK) == CLOCKFD);
+}
+
#ifdef CONFIG_POSIX_TIMERS

/**
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index bf540f5a4115..806465233303 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -1400,7 +1400,7 @@ static const struct k_clock *clockid_to_kclock(const clockid_t id)
clockid_t idx = id;

if (id < 0) {
- return (id & CLOCKFD_MASK) == CLOCKFD ?
+ return is_clockid_fd_clock(id) ?
&clock_posix_dynamic : &clock_posix_cpu;
}

--
2.20.1