aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-05-04 14:04:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-04 20:21:58 -0400
commitc728b9c87b59fb943c4cba0552d38152787a4ab6 (patch)
tree072a4bac6686701ef46eca2fabb06306c400391b
parent321310ced2d6cc0175c76fa512fa8a829ee35223 (diff)
ipc: simplify semtimedop/semctl_main() common error path handling
With various straight RCU lock/unlock movements, one common exit path pattern had become rcu_read_unlock(); goto out_wakeup; and in fact there were no cases where we wanted to exit to out_wakeup _without_ releasing the RCU read lock. So replace that pattern with "goto out_rcu_wakeup", and remove the old out_wakeup. Acked-by: Davidlohr Bueso <davidlohr.bueso@hp.com> Cc: Rik van Riel <riel@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--ipc/sem.c41
1 files changed, 14 insertions, 27 deletions
diff --git a/ipc/sem.c b/ipc/sem.c
index 8486a5bb6d29..f2151babd26a 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1077,17 +1077,12 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1077 nsems = sma->sem_nsems; 1077 nsems = sma->sem_nsems;
1078 1078
1079 err = -EACCES; 1079 err = -EACCES;
1080 if (ipcperms(ns, &sma->sem_perm, 1080 if (ipcperms(ns, &sma->sem_perm, cmd == SETALL ? S_IWUGO : S_IRUGO))
1081 cmd == SETALL ? S_IWUGO : S_IRUGO)) { 1081 goto out_rcu_wakeup;
1082 rcu_read_unlock();
1083 goto out_wakeup;
1084 }
1085 1082
1086 err = security_sem_semctl(sma, cmd); 1083 err = security_sem_semctl(sma, cmd);
1087 if (err) { 1084 if (err)
1088 rcu_read_unlock(); 1085 goto out_rcu_wakeup;
1089 goto out_wakeup;
1090 }
1091 1086
1092 err = -EACCES; 1087 err = -EACCES;
1093 switch (cmd) { 1088 switch (cmd) {
@@ -1188,10 +1183,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1188 /* GETVAL, GETPID, GETNCTN, GETZCNT: fall-through */ 1183 /* GETVAL, GETPID, GETNCTN, GETZCNT: fall-through */
1189 } 1184 }
1190 err = -EINVAL; 1185 err = -EINVAL;
1191 if (semnum < 0 || semnum >= nsems) { 1186 if (semnum < 0 || semnum >= nsems)
1192 rcu_read_unlock(); 1187 goto out_rcu_wakeup;
1193 goto out_wakeup;
1194 }
1195 1188
1196 sem_lock(sma, NULL, -1); 1189 sem_lock(sma, NULL, -1);
1197 curr = &sma->sem_base[semnum]; 1190 curr = &sma->sem_base[semnum];
@@ -1213,8 +1206,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1213 1206
1214out_unlock: 1207out_unlock:
1215 sem_unlock(sma, -1); 1208 sem_unlock(sma, -1);
1209out_rcu_wakeup:
1216 rcu_read_unlock(); 1210 rcu_read_unlock();
1217out_wakeup:
1218 wake_up_sem_queue_do(&tasks); 1211 wake_up_sem_queue_do(&tasks);
1219out_free: 1212out_free:
1220 if(sem_io != fast_sem_io) 1213 if(sem_io != fast_sem_io)
@@ -1585,22 +1578,16 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
1585 } 1578 }
1586 1579
1587 error = -EFBIG; 1580 error = -EFBIG;
1588 if (max >= sma->sem_nsems) { 1581 if (max >= sma->sem_nsems)
1589 rcu_read_unlock(); 1582 goto out_rcu_wakeup;
1590 goto out_wakeup;
1591 }
1592 1583
1593 error = -EACCES; 1584 error = -EACCES;
1594 if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO)) { 1585 if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO))
1595 rcu_read_unlock(); 1586 goto out_rcu_wakeup;
1596 goto out_wakeup;
1597 }
1598 1587
1599 error = security_sem_semop(sma, sops, nsops, alter); 1588 error = security_sem_semop(sma, sops, nsops, alter);
1600 if (error) { 1589 if (error)
1601 rcu_read_unlock(); 1590 goto out_rcu_wakeup;
1602 goto out_wakeup;
1603 }
1604 1591
1605 /* 1592 /*
1606 * semid identifiers are not unique - find_alloc_undo may have 1593 * semid identifiers are not unique - find_alloc_undo may have
@@ -1718,8 +1705,8 @@ sleep_again:
1718 1705
1719out_unlock_free: 1706out_unlock_free:
1720 sem_unlock(sma, locknum); 1707 sem_unlock(sma, locknum);
1708out_rcu_wakeup:
1721 rcu_read_unlock(); 1709 rcu_read_unlock();
1722out_wakeup:
1723 wake_up_sem_queue_do(&tasks); 1710 wake_up_sem_queue_do(&tasks);
1724out_free: 1711out_free:
1725 if(sops != fast_sops) 1712 if(sops != fast_sops)