Skip to contentSkip to conversation

nfc: llcp: clear device pointer on disconnect

PATCH New Aldo Ariel Panzardo 1 participant 1 message Sep 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfc: llcp: clear device pointer on disconnect

nfc_llcp_recv_disc() drops the device reference via nfc_put_device() when a connected socket receives a DISC PDU, but does not clear llcp_sock->dev. If the socket is later reconnected, any cleanup code that checks llcp_sock->dev will find a non-NULL pointer and attempt a second nfc_put_device(), underflowing the device refcount.

Clear the pointer immediately after the put so that a subsequent reconnect does not double-release the device.

Fixes d646960f7986 ("NFC: Initial LLCP support")
---
 net/nfc/llcp_core.c | 1 +
 1 file changed, 1 insertion(+)
net/nfc/llcp_core.c +1 -0
index 74bf81700..199543c47 100644
@@ -1220,6 +1220,7 @@ static void nfc_llcp_recv_disc(struct nfc_llcp_local *local,
 
 	if (sk->sk_state == LLCP_CONNECTED) {
 		nfc_put_device(local->dev);
+		llcp_sock->dev = NULL;
 		sk->sk_state = LLCP_CLOSED;
 		sk->sk_state_change(sk);
 	}
Signature · 1 line
2.43.0