Skip to contentSkip to conversation

nfc: llcp: avoid double release/put on LLCP_CLOSED in nfc_llcp_recv_disc()

PATCH Superseded Qianchang Zhao 2 participants 2 messages Dec 17, 2025

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfc: llcp: avoid double release/put on LLCP_CLOSED in nfc_llcp_recv_disc()

nfc_llcp_sock_get() takes a reference on the LLCP socket via sock_hold().

In nfc_llcp_recv_disc(), when the socket is already in LLCP_CLOSED state, the code used to perform release_sock() and nfc_llcp_sock_put() in the CLOSED branch but then continued execution and later performed the same cleanup again on the common exit path. This results in refcount imbalance (double put) and unbalanced lock release.

Remove the redundant CLOSED-branch cleanup so that release_sock() and nfc_llcp_sock_put() are performed exactly once via the common exit path, while keeping the existing DM_DISC reply behavior.

---
 net/nfc/llcp_core.c | 5 -----
 1 file changed, 5 deletions(-)
net/nfc/llcp_core.c +0 -5
index beeb3b4d2..ed37604ed 100644
@@ -1177,11 +1177,6 @@ static void nfc_llcp_recv_disc(struct nfc_llcp_local *local,
 
 	nfc_llcp_socket_purge(llcp_sock);
 
-	if (sk->sk_state == LLCP_CLOSED) {
-		release_sock(sk);
-		nfc_llcp_sock_put(llcp_sock);
-	}
-
 	if (sk->sk_state == LLCP_CONNECTED) {
 		nfc_put_device(local->dev);
 		sk->sk_state = LLCP_CLOSED;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Qianchang Zhao

nfc_llcp_sock_get() takes a reference on the LLCP socket via sock_hold().

In nfc_llcp_recv_disc(), when the socket is already in LLCP_CLOSED state, the code used to perform release_sock() and nfc_llcp_sock_put() in the CLOSED branch but then continued execution and later performed the same cleanup again on the common exit path. This results in refcount imbalance (double put) and unbalanced lock release.

You did not answer to my questions, so I repeat the same question I already asked you. Don't ignore reviewer's feedback.

Quoted 7 lines

Remove the redundant CLOSED-branch cleanup so that release_sock() and nfc_llcp_sock_put() are performed exactly once via the common exit path, while keeping the existing DM_DISC reply behavior.

Drop both. You are the author, there are no reported-by credits for authors.

Missing Fixes tag.

Quoted 11 lines
---
 net/nfc/llcp_core.c | 5 -----
 1 file changed, 5 deletions(-)
net/nfc/llcp_core.c +0 -0
index beeb3b4d2..ed37604ed 100644

net/nfc/llcp_core.c static void nfc_llcp_recv_disc(struct nfc_llcp_local *local, · line 1182

Quoted 6 lines
net/nfc/llcp_core.c +0 -3
@@ -1177,11 +1177,6 @@ static void nfc_llcp_recv_disc(struct nfc_llcp_local *local,
 
 	nfc_llcp_socket_purge(llcp_sock);
 
-	if (sk->sk_state == LLCP_CLOSED) {
-		release_sock(sk);
-		nfc_llcp_sock_put(llcp_sock);

So why now sending to closed socket is right?

net/nfc/llcp_core.c static void nfc_llcp_recv_disc(struct nfc_llcp_local *local, · line 1182

Quoted 5 lines
net/nfc/llcp_core.c +0 -2
-	}
-
 	if (sk->sk_state == LLCP_CONNECTED) {
 		nfc_put_device(local->dev);
 		sk->sk_state = LLCP_CLOSED;

Best regards,
Krzysztof