Skip to content

Commit 48766a5

Browse files
Tung Nguyendavem330
authored andcommitted
tipc: improve function tipc_wait_for_rcvmsg()
This commit replaces schedule_timeout() with wait_woken() in function tipc_wait_for_rcvmsg(). wait_woken() uses memory barriers in its implementation to avoid potential race condition when putting a process into sleeping state and then waking it up. Acked-by: Ying Xue <ying.xue@windriver.com> Acked-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: Tung Nguyen <tung.q.nguyen@dektech.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 223b732 commit 48766a5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

net/tipc/socket.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,23 +1677,25 @@ static void tipc_sk_send_ack(struct tipc_sock *tsk)
16771677
static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop)
16781678
{
16791679
struct sock *sk = sock->sk;
1680-
DEFINE_WAIT(wait);
1680+
DEFINE_WAIT_FUNC(wait, woken_wake_function);
16811681
long timeo = *timeop;
16821682
int err = sock_error(sk);
16831683

16841684
if (err)
16851685
return err;
16861686

16871687
for (;;) {
1688-
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
16891688
if (timeo && skb_queue_empty(&sk->sk_receive_queue)) {
16901689
if (sk->sk_shutdown & RCV_SHUTDOWN) {
16911690
err = -ENOTCONN;
16921691
break;
16931692
}
1693+
add_wait_queue(sk_sleep(sk), &wait);
16941694
release_sock(sk);
1695-
timeo = schedule_timeout(timeo);
1695+
timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, timeo);
1696+
sched_annotate_sleep();
16961697
lock_sock(sk);
1698+
remove_wait_queue(sk_sleep(sk), &wait);
16971699
}
16981700
err = 0;
16991701
if (!skb_queue_empty(&sk->sk_receive_queue))
@@ -1709,7 +1711,6 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop)
17091711
if (err)
17101712
break;
17111713
}
1712-
finish_wait(sk_sleep(sk), &wait);
17131714
*timeop = timeo;
17141715
return err;
17151716
}

0 commit comments

Comments
 (0)