aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/l2cap_sock.c
diff options
context:
space:
mode:
authorDean Jenkins <Dean_Jenkins@mentor.com>2015-10-14 06:18:45 -0400
committerMarcel Holtmann <marcel@holtmann.org>2015-10-20 18:49:26 -0400
commite7456437c15a2fd42cedd25c2b12b06876f285f0 (patch)
tree87c6a143827fc5c107464ae2366af8ba42af095a /net/bluetooth/l2cap_sock.c
parent09bf420f101c9d35ca0b5f539c7f03951fd2e24d (diff)
Bluetooth: Unwind l2cap_sock_shutdown()
l2cap_sock_shutdown() is designed to only action shutdown of the channel when shutdown is not already in progress. Therefore, reorganise the code flow by adding a goto to jump to the end of function handling when shutdown is already being actioned. This removes one level of code indentation and make the code more readable. Signed-off-by: Dean Jenkins <Dean_Jenkins@mentor.com> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/l2cap_sock.c')
-rw-r--r--net/bluetooth/l2cap_sock.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 586b3d580cfc..ca5598d6a201 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1111,6 +1111,11 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
1111 if (!sk) 1111 if (!sk)
1112 return 0; 1112 return 0;
1113 1113
1114 if (sk->sk_shutdown)
1115 goto shutdown_already;
1116
1117 BT_DBG("Handling sock shutdown");
1118
1114 /* prevent sk structure from being freed whilst unlocked */ 1119 /* prevent sk structure from being freed whilst unlocked */
1115 sock_hold(sk); 1120 sock_hold(sk);
1116 1121
@@ -1127,23 +1132,21 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
1127 l2cap_chan_lock(chan); 1132 l2cap_chan_lock(chan);
1128 lock_sock(sk); 1133 lock_sock(sk);
1129 1134
1130 if (!sk->sk_shutdown) { 1135 if (chan->mode == L2CAP_MODE_ERTM &&
1131 if (chan->mode == L2CAP_MODE_ERTM && 1136 chan->unacked_frames > 0 &&
1132 chan->unacked_frames > 0 && 1137 chan->state == BT_CONNECTED)
1133 chan->state == BT_CONNECTED) 1138 err = __l2cap_wait_ack(sk, chan);
1134 err = __l2cap_wait_ack(sk, chan);
1135 1139
1136 sk->sk_shutdown = SHUTDOWN_MASK; 1140 sk->sk_shutdown = SHUTDOWN_MASK;
1137 1141
1138 release_sock(sk); 1142 release_sock(sk);
1139 l2cap_chan_close(chan, 0); 1143 l2cap_chan_close(chan, 0);
1140 lock_sock(sk); 1144 lock_sock(sk);
1141 1145
1142 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime && 1146 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
1143 !(current->flags & PF_EXITING)) 1147 !(current->flags & PF_EXITING))
1144 err = bt_sock_wait_state(sk, BT_CLOSED, 1148 err = bt_sock_wait_state(sk, BT_CLOSED,
1145 sk->sk_lingertime); 1149 sk->sk_lingertime);
1146 }
1147 1150
1148 if (!err && sk->sk_err) 1151 if (!err && sk->sk_err)
1149 err = -sk->sk_err; 1152 err = -sk->sk_err;
@@ -1157,6 +1160,7 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
1157 l2cap_chan_put(chan); 1160 l2cap_chan_put(chan);
1158 sock_put(sk); 1161 sock_put(sk);
1159 1162
1163shutdown_already:
1160 BT_DBG("err: %d", err); 1164 BT_DBG("err: %d", err);
1161 1165
1162 return err; 1166 return err;