Skip to content

Commit

Permalink
posix-timers: sys_timer_create: cleanup the error handling
Browse files Browse the repository at this point in the history
Cleanup.

- sys_timer_create() is big and complicated. The code above the "out:"
  label relies on the fact that "error" must be == 0. This is not very
  robust, make the code more explicit. Remove the unneeded initialization
  of error.

- If idr_get_new() succeeds (as it normally should), we check the returned
  value twice. Move the "-EAGAIN" check under "if (error)".

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 717835d commit ef864c9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions kernel/posix-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,8 @@ sys_timer_create(const clockid_t which_clock,
struct sigevent __user *timer_event_spec,
timer_t __user * created_timer_id)
{
int error = 0;
struct k_itimer *new_timer;
int new_timer_id;
int error, new_timer_id;
struct task_struct *process;
sigevent_t event;
int it_id_set = IT_ID_NOT_SET;
Expand All @@ -478,9 +477,9 @@ sys_timer_create(const clockid_t which_clock,
error = idr_get_new(&posix_timers_id, (void *) new_timer,
&new_timer_id);
spin_unlock_irq(&idr_lock);
if (error == -EAGAIN)
goto retry;
else if (error) {
if (error) {
if (error == -EAGAIN)
goto retry;
/*
* Weird looking, but we return EAGAIN if the IDR is
* full (proper POSIX return value for this)
Expand Down Expand Up @@ -541,16 +540,16 @@ sys_timer_create(const clockid_t which_clock,
new_timer->it_process = process;
list_add(&new_timer->list, &current->signal->posix_timers);
spin_unlock_irq(&current->sighand->siglock);

return 0;
/*
* In the case of the timer belonging to another task, after
* the task is unlocked, the timer is owned by the other task
* and may cease to exist at any time. Don't use or modify
* new_timer after the unlock call.
*/
out:
if (error)
release_posix_timer(new_timer, it_id_set);

release_posix_timer(new_timer, it_id_set);
return error;
}

Expand Down

0 comments on commit ef864c9

Please sign in to comment.