Skip to content

Commit f150f02

Browse files
Davidlohr Buesotorvalds
authored andcommitted
ipc/sem: use proper list api for pending_list wakeups
... saves some LoC and looks cleaner than re-implementing the calls. Link: http://lkml.kernel.org/r/1474225896-10066-6-git-send-email-dave@stgolabs.net Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Acked-by: Manfred Spraul <manfred@colorfullife.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4663d3e commit f150f02

1 file changed

Lines changed: 13 additions & 25 deletions

File tree

‎ipc/sem.c‎

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,7 @@ static inline int check_restart(struct sem_array *sma, struct sem_queue *q)
813813
static int wake_const_ops(struct sem_array *sma, int semnum,
814814
struct wake_q_head *wake_q)
815815
{
816-
struct sem_queue *q;
817-
struct list_head *walk;
816+
struct sem_queue *q, *tmp;
818817
struct list_head *pending_list;
819818
int semop_completed = 0;
820819

@@ -823,25 +822,19 @@ static int wake_const_ops(struct sem_array *sma, int semnum,
823822
else
824823
pending_list = &sma->sem_base[semnum].pending_const;
825824

826-
walk = pending_list->next;
827-
while (walk != pending_list) {
828-
int error;
829-
830-
q = container_of(walk, struct sem_queue, list);
831-
walk = walk->next;
832-
833-
error = perform_atomic_semop(sma, q);
834-
835-
if (error <= 0) {
836-
/* operation completed, remove from queue & wakeup */
825+
list_for_each_entry_safe(q, tmp, pending_list, list) {
826+
int error = perform_atomic_semop(sma, q);
837827

838-
unlink_queue(sma, q);
828+
if (error > 0)
829+
continue;
830+
/* operation completed, remove from queue & wakeup */
831+
unlink_queue(sma, q);
839832

840-
wake_up_sem_queue_prepare(q, error, wake_q);
841-
if (error == 0)
842-
semop_completed = 1;
843-
}
833+
wake_up_sem_queue_prepare(q, error, wake_q);
834+
if (error == 0)
835+
semop_completed = 1;
844836
}
837+
845838
return semop_completed;
846839
}
847840

@@ -914,8 +907,7 @@ static int do_smart_wakeup_zero(struct sem_array *sma, struct sembuf *sops,
914907
*/
915908
static int update_queue(struct sem_array *sma, int semnum, struct wake_q_head *wake_q)
916909
{
917-
struct sem_queue *q;
918-
struct list_head *walk;
910+
struct sem_queue *q, *tmp;
919911
struct list_head *pending_list;
920912
int semop_completed = 0;
921913

@@ -925,13 +917,9 @@ static int update_queue(struct sem_array *sma, int semnum, struct wake_q_head *w
925917
pending_list = &sma->sem_base[semnum].pending_alter;
926918

927919
again:
928-
walk = pending_list->next;
929-
while (walk != pending_list) {
920+
list_for_each_entry_safe(q, tmp, pending_list, list) {
930921
int error, restart;
931922

932-
q = container_of(walk, struct sem_queue, list);
933-
walk = walk->next;
934-
935923
/* If we are scanning the single sop, per-semaphore list of
936924
* one semaphore and that semaphore is 0, then it is not
937925
* necessary to scan further: simple increments

0 commit comments

Comments
 (0)