Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef864c95 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Thomas Gleixner
Browse files

posix-timers: sys_timer_create: cleanup the error handling



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: default avatarOleg Nesterov <oleg@tv-sign.ru>
Cc: mingo@elte.hu
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 717835d9
Loading
Loading
Loading
Loading
+7 −8
Original line number Original line Diff line number Diff line
@@ -454,9 +454,8 @@ sys_timer_create(const clockid_t which_clock,
		 struct sigevent __user *timer_event_spec,
		 struct sigevent __user *timer_event_spec,
		 timer_t __user * created_timer_id)
		 timer_t __user * created_timer_id)
{
{
	int error = 0;
	struct k_itimer *new_timer;
	struct k_itimer *new_timer;
	int new_timer_id;
	int error, new_timer_id;
	struct task_struct *process;
	struct task_struct *process;
	sigevent_t event;
	sigevent_t event;
	int it_id_set = IT_ID_NOT_SET;
	int it_id_set = IT_ID_NOT_SET;
@@ -478,9 +477,9 @@ sys_timer_create(const clockid_t which_clock,
	error = idr_get_new(&posix_timers_id, (void *) new_timer,
	error = idr_get_new(&posix_timers_id, (void *) new_timer,
			    &new_timer_id);
			    &new_timer_id);
	spin_unlock_irq(&idr_lock);
	spin_unlock_irq(&idr_lock);
	if (error) {
		if (error == -EAGAIN)
		if (error == -EAGAIN)
			goto retry;
			goto retry;
	else if (error) {
		/*
		/*
		 * Weird looking, but we return EAGAIN if the IDR is
		 * Weird looking, but we return EAGAIN if the IDR is
		 * full (proper POSIX return value for this)
		 * full (proper POSIX return value for this)
@@ -541,6 +540,8 @@ sys_timer_create(const clockid_t which_clock,
	new_timer->it_process = process;
	new_timer->it_process = process;
	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
	 * In the case of the timer belonging to another task, after
	 * the task is unlocked, the timer is owned by the other task
	 * the task is unlocked, the timer is owned by the other task
@@ -548,9 +549,7 @@ sys_timer_create(const clockid_t which_clock,
	 * new_timer after the unlock call.
	 * new_timer after the unlock call.
	 */
	 */
out:
out:
	if (error)
	release_posix_timer(new_timer, it_id_set);
	release_posix_timer(new_timer, it_id_set);

	return error;
	return error;
}
}