Bluetooth: L2CAP: missing NULL guard in remaining l2cap_chan_ops callbacks

From: y2k

Date: Fri May 08 2026 - 16:24:36 EST


Commits 0a120d961663, 78a88d43dab8, and 2ff1a41a912d added NULL guards
for chan->data in l2cap_sock_new_connection_cb(), l2cap_sock_get_sndtimeo_cb(),
and l2cap_sock_state_change_cb() respectively.

The same NULL guard is still missing in five other l2cap_chan_ops callbacks
in net/bluetooth/l2cap_sock.c:

- l2cap_sock_defer_cb() (.defer)
- l2cap_sock_suspend_cb() (.suspend)
- l2cap_sock_set_shutdown_cb() (.set_shutdown)
- l2cap_sock_get_peer_pid_cb() (.get_peer_pid)
- l2cap_sock_filter() (.filter)

All five dereference chan->data directly without checking for NULL:

struct sock *sk = chan->data;
lock_sock(sk); /* or direct sk-> access */

The fix mirrors the existing guards:

struct sock *sk = chan->data;
if (!sk)
return; /* or appropriate return value */

Fixes: 80808e431e1e ("Bluetooth: Add l2cap_chan_ops abstraction")
Reported-by: y2k <y2k@xxxxxxxxxxxxxxxxx>

Thanks,
y2k
y2k@xxxxxxxxxxxxxxxxx