Skip to contentSkip to conversation

posix-timers: sys_timer_create: cleanup the error handling

PATCH New Oleg Nesterov 1 participant 1 message Aug 4, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 4/4 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)".

kernel/posix-timers.c renamed from kernel/posix-timers.c~7_ERROR +7 -7
@@ -454,7 +454,7 @@ sys_timer_create(const clockid_t which_c
 		 struct sigevent __user *timer_event_spec,
 		 timer_t __user * created_timer_id)
 {
-	int error = 0;
+	int error;
 	struct k_itimer *new_timer;
 	int new_timer_id;
 	struct task_struct *process;
@@ -478,9 +478,9 @@ sys_timer_create(const clockid_t which_c
 	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)
@@ -541,6 +541,8 @@ sys_timer_create(const clockid_t which_c
 	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
@@ -548,9 +550,7 @@ sys_timer_create(const clockid_t which_c
 	 * 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;
 }