static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
                               struct itimerspec64 *new, struct itimerspec64 *old)
 {
-       unsigned long flags;
-       struct sighand_struct *sighand;
-       struct task_struct *p = timer->it.cpu.task;
+       clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock);
        u64 old_expires, new_expires, old_incr, val;
+       struct task_struct *p = timer->it.cpu.task;
+       struct sighand_struct *sighand;
+       unsigned long flags;
        int ret;
 
        if (WARN_ON_ONCE(!p))
         * check if it's already passed.  In short, we need a sample.
         */
        if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
-               cpu_clock_sample(timer->it_clock, p, &val);
+               cpu_clock_sample(clkid, p, &val);
        } else {
-               cpu_clock_sample_group(timer->it_clock, p, &val, true);
+               cpu_clock_sample_group(clkid, p, &val, true);
        }
 
        if (old) {