Skip to content

Commit 8cc96ca

Browse files
committed
posix-timers: Split release_posix_timers()
release_posix_timers() is called for cleaning up both hashed and unhashed timers. The cases are differentiated by an argument and the usage is hideous. Seperate the actual free path out and use it for unhashed timers. Provide a function for hashed timers. No functional change. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://lore.kernel.org/r/20230425183313.301432503@linutronix.de
1 parent 11fbe6c commit 8cc96ca

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

kernel/time/posix-timers.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -466,20 +466,21 @@ static void k_itimer_rcu_free(struct rcu_head *head)
466466
kmem_cache_free(posix_timers_cache, tmr);
467467
}
468468

469-
#define IT_ID_SET 1
470-
#define IT_ID_NOT_SET 0
471-
static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
472-
{
473-
if (it_id_set) {
474-
spin_lock(&hash_lock, flags);
475-
hlist_del_rcu(&tmr->t_hash);
476-
spin_unlock(&hash_lock, flags);
477-
}
469+
static void posix_timer_free(struct k_itimer *tmr)
470+
{
478471
put_pid(tmr->it_pid);
479472
sigqueue_free(tmr->sigq);
480473
call_rcu(&tmr->rcu, k_itimer_rcu_free);
481474
}
482475

476+
static void posix_timer_unhash_and_free(struct k_itimer *tmr)
477+
{
478+
spin_lock(&hash_lock);
479+
hlist_del_rcu(&tmr->t_hash);
480+
spin_unlock(&hash_lock);
481+
posix_timer_free(tmr);
482+
}
483+
483484
static int common_timer_create(struct k_itimer *new_timer)
484485
{
485486
hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0);
@@ -493,7 +494,6 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
493494
const struct k_clock *kc = clockid_to_kclock(which_clock);
494495
struct k_itimer *new_timer;
495496
int error, new_timer_id;
496-
int it_id_set = IT_ID_NOT_SET;
497497

498498
if (!kc)
499499
return -EINVAL;
@@ -513,11 +513,10 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
513513
*/
514514
new_timer_id = posix_timer_add(new_timer);
515515
if (new_timer_id < 0) {
516-
error = new_timer_id;
517-
goto out;
516+
posix_timer_free(new_timer);
517+
return new_timer_id;
518518
}
519519

520-
it_id_set = IT_ID_SET;
521520
new_timer->it_id = (timer_t) new_timer_id;
522521
new_timer->it_clock = which_clock;
523522
new_timer->kclock = kc;
@@ -569,7 +568,7 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
569568
* new_timer after the unlock call.
570569
*/
571570
out:
572-
release_posix_timer(new_timer, it_id_set);
571+
posix_timer_unhash_and_free(new_timer);
573572
return error;
574573
}
575574

@@ -1057,7 +1056,7 @@ SYSCALL_DEFINE1(timer_delete, timer_t, timer_id)
10571056
WRITE_ONCE(timer->it_signal, NULL);
10581057

10591058
unlock_timer(timer, flags);
1060-
release_posix_timer(timer, IT_ID_SET);
1059+
posix_timer_unhash_and_free(timer);
10611060
return 0;
10621061
}
10631062

@@ -1109,7 +1108,7 @@ static void itimer_delete(struct k_itimer *timer)
11091108
WRITE_ONCE(timer->it_signal, NULL);
11101109

11111110
spin_unlock_irqrestore(&timer->it_lock, flags);
1112-
release_posix_timer(timer, IT_ID_SET);
1111+
posix_timer_unhash_and_free(timer);
11131112
}
11141113

11151114
/*

0 commit comments

Comments
 (0)