Commit 52f090b1 authored by Thomas Gleixner's avatar Thomas Gleixner

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: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Link: https://lore.kernel.org/r/20230425183313.619897296@linutronix.de
parent 640fe745
...@@ -529,12 +529,17 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event, ...@@ -529,12 +529,17 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
new_timer->sigq->info.si_tid = new_timer->it_id; new_timer->sigq->info.si_tid = new_timer->it_id;
new_timer->sigq->info.si_code = SI_TIMER; new_timer->sigq->info.si_code = SI_TIMER;
if (copy_to_user(created_timer_id, if (copy_to_user(created_timer_id, &new_timer_id, sizeof (new_timer_id))) {
&new_timer_id, sizeof (new_timer_id))) {
error = -EFAULT; error = -EFAULT;
goto out; goto out;
} }
/*
* After succesful copy out, the timer ID is visible to user space
* now but not yet valid because new_timer::signal is still NULL.
*
* Complete the initialization with the clock specific create
* callback.
*/
error = kc->timer_create(new_timer); error = kc->timer_create(new_timer);
if (error) if (error)
goto out; goto out;
...@@ -544,14 +549,11 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event, ...@@ -544,14 +549,11 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
WRITE_ONCE(new_timer->it_signal, current->signal); WRITE_ONCE(new_timer->it_signal, current->signal);
list_add(&new_timer->list, &current->signal->posix_timers); list_add(&new_timer->list, &current->signal->posix_timers);
spin_unlock_irq(&current->sighand->siglock); spin_unlock_irq(&current->sighand->siglock);
return 0;
/* /*
* In the case of the timer belonging to another task, after * After unlocking sighand::siglock @new_timer is subject to
* the task is unlocked, the timer is owned by the other task * concurrent removal and cannot be touched anymore
* and may cease to exist at any time. Don't use or modify
* new_timer after the unlock call.
*/ */
return 0;
out: out:
posix_timer_unhash_and_free(new_timer); posix_timer_unhash_and_free(new_timer);
return error; return error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment