Skip to content

Commit

Permalink
posix-timers: lock_timer: kill the bogus ->it_id check
Browse files Browse the repository at this point in the history
lock_timer() checks that the timer found by idr_find(timer_id) has ->it_id
== timer_id.  This buys nothing.  This check can fail only if
sys_timer_create() unlocked idr_lock after idr_get_new(), but didn't set
->it_id = new_timer_id yet.  But in that case ->it_process == NULL so
lock_timer() can't succeed anyway.

Also remove a couple of unneeded typecasts.

Note that with or without this patch we have a small problem. 
sys_timer_create() doesn't ensure that the result of setting (say)
->it_sigev_notify must be visible if lock_timer() succeeds.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: mingo@elte.hu
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Oleg Nesterov authored and Thomas Gleixner committed Sep 24, 2008
1 parent 5a9fa73 commit 5a51b71
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions kernel/posix-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ sys_timer_create(const clockid_t which_clock,
goto out;
}
spin_lock_irq(&idr_lock);
error = idr_get_new(&posix_timers_id, (void *) new_timer,
&new_timer_id);
error = idr_get_new(&posix_timers_id, new_timer, &new_timer_id);
spin_unlock_irq(&idr_lock);
if (error) {
if (error == -EAGAIN)
Expand Down Expand Up @@ -567,12 +566,12 @@ static struct k_itimer * lock_timer(timer_t timer_id, unsigned long *flags)
*/

spin_lock_irqsave(&idr_lock, *flags);
timr = (struct k_itimer *) idr_find(&posix_timers_id, (int) timer_id);
timr = idr_find(&posix_timers_id, (int) timer_id);
if (timr) {
spin_lock(&timr->it_lock);

if ((timr->it_id != timer_id) || !(timr->it_process) ||
!same_thread_group(timr->it_process, current)) {
if (!timr->it_process ||
!same_thread_group(timr->it_process, current)) {
spin_unlock(&timr->it_lock);
spin_unlock_irqrestore(&idr_lock, *flags);
timr = NULL;
Expand Down

0 comments on commit 5a51b71

Please sign in to comment.