>From e713b2e8ae93aa46465984237247698d18f6a671 Mon Sep 17 00:00:00 2001 From: Ville Tervo Date: Fri, 26 Feb 2010 12:21:01 +0200 Subject: [PATCH] Bluetooth: Drop rfcomm session reference only once for incoming session Move decision to drop reference for incoming session to rfcomm_session_close to get more clear rfcomm_session_hold()/rfcomm_session_put() pairs. Signed-off-by: Ville Tervo --- net/bluetooth/rfcomm/core.c | 23 ++++++++++------------- 1 files changed, 10 insertions(+), 13 deletions(-) diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index 89f4a59..adccd92 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -662,6 +662,9 @@ static void rfcomm_session_close(struct rfcomm_session *s, int err) BT_DBG("session %p state %ld err %d", s, s->state, err); + if (s->state == BT_CLOSED) + return; + rfcomm_session_hold(s); s->state = BT_CLOSED; @@ -674,6 +677,11 @@ static void rfcomm_session_close(struct rfcomm_session *s, int err) } rfcomm_session_clear_timer(s); + + /* Drop reference for incoming sessions */ + if (!s->initiator) + rfcomm_session_put(s); + rfcomm_session_put(s); } @@ -1150,11 +1158,7 @@ static int rfcomm_recv_ua(struct rfcomm_session *s, u8 dlci) break; case BT_DISCONN: - /* When socket is closed and we are not RFCOMM - * initiator rfcomm_process_rx already calls - * rfcomm_session_put() */ - if (s->sock->sk->sk_state != BT_CLOSED) - rfcomm_session_put(s); + rfcomm_session_close(s, 0); break; } } @@ -1185,7 +1189,6 @@ static int rfcomm_recv_dm(struct rfcomm_session *s, u8 dlci) else err = ECONNRESET; - s->state = BT_CLOSED; rfcomm_session_close(s, err); } return 0; @@ -1220,7 +1223,6 @@ static int rfcomm_recv_disc(struct rfcomm_session *s, u8 dlci) else err = ECONNRESET; - s->state = BT_CLOSED; rfcomm_session_close(s, err); } @@ -1845,12 +1847,8 @@ static inline void rfcomm_process_rx(struct rfcomm_session *s) rfcomm_recv_frame(s, skb); } - if (sk->sk_state == BT_CLOSED) { - if (!s->initiator) - rfcomm_session_put(s); - + if (sk->sk_state == BT_CLOSED) rfcomm_session_close(s, sk->sk_err); - } } static inline void rfcomm_accept_connection(struct rfcomm_session *s) @@ -1904,7 +1902,6 @@ static inline void rfcomm_check_connection(struct rfcomm_session *s) break; case BT_CLOSED: - s->state = BT_CLOSED; rfcomm_session_close(s, sk->sk_err); break; } -- 1.6.4.4