Skip to content

Commit 52f090b

Browse files
committed
posix-timers: Add proper comments in do_timer_create()
The comment about timer lifetime at the end of the function is misplaced and uncomprehensible. Make it understandable and put it at the right place. Add a new comment about the visibility of the new timer ID to user space. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://lore.kernel.org/r/20230425183313.619897296@linutronix.de
1 parent 640fe74 commit 52f090b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

kernel/time/posix-timers.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,17 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
529529
new_timer->sigq->info.si_tid = new_timer->it_id;
530530
new_timer->sigq->info.si_code = SI_TIMER;
531531

532-
if (copy_to_user(created_timer_id,
533-
&new_timer_id, sizeof (new_timer_id))) {
532+
if (copy_to_user(created_timer_id, &new_timer_id, sizeof (new_timer_id))) {
534533
error = -EFAULT;
535534
goto out;
536535
}
537-
536+
/*
537+
* After succesful copy out, the timer ID is visible to user space
538+
* now but not yet valid because new_timer::signal is still NULL.
539+
*
540+
* Complete the initialization with the clock specific create
541+
* callback.
542+
*/
538543
error = kc->timer_create(new_timer);
539544
if (error)
540545
goto out;
@@ -544,14 +549,11 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
544549
WRITE_ONCE(new_timer->it_signal, current->signal);
545550
list_add(&new_timer->list, &current->signal->posix_timers);
546551
spin_unlock_irq(&current->sighand->siglock);
547-
548-
return 0;
549552
/*
550-
* In the case of the timer belonging to another task, after
551-
* the task is unlocked, the timer is owned by the other task
552-
* and may cease to exist at any time. Don't use or modify
553-
* new_timer after the unlock call.
553+
* After unlocking sighand::siglock @new_timer is subject to
554+
* concurrent removal and cannot be touched anymore
554555
*/
556+
return 0;
555557
out:
556558
posix_timer_unhash_and_free(new_timer);
557559
return error;

0 commit comments

Comments
 (0)