]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
net: wwan: core: explicit WWAN device reference counting
authorSergey Ryazanov <ryazanov.s.a@gmail.com>
Mon, 26 Jan 2026 06:21:52 +0000 (14:21 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 31 Jan 2026 02:26:59 +0000 (18:26 -0800)
commitb9879ba78dca3da61448b52751551da2bb52469c
tree537c59c967ed72d01276e7fe452a9a597ebfa9f3
parentd95c5aa45231400f9ecfd4b2cbf093e7c7accd8b
net: wwan: core: explicit WWAN device reference counting

We need information about existing WWAN device children since we remove
the device after removing the last child. Previously, we tracked users
implicitly by checking whether ops was registered and existence of a
child device of the wwan_class class. Upcoming GNSS (NMEA) port type
support breaks this approach by introducing a child device of the
gnss_class class.

And a modem driver can easily trigger a kernel Oops by removing regular
(e.g., MBIM, AT) ports first and then removing a GNSS port. The WWAN
device will be unregistered on removal of a last regular WWAN port. And
subsequent GNSS port removal will cause NULL pointer dereference in
simple_recursive_removal().

In order to support ports of classes other than wwan_class, switch to
explicit references counting. Introduce a dedicated counter to the WWAN
device struct, increment it on every wwan_create_dev() call, decrement
on wwan_remove_dev(), and actually unregister the WWAN device when there
are no more references.

Run tested with wwan_hwsim with NMEA support patches applied and
different port removing sequences.

Reported-by: Daniele Palmas <dnlplm@gmail.com>
Closes: https://lore.kernel.org/netdev/CAGRyCJE28yf-rrfkFbzu44ygLEvoUM7fecK1vnrghjG_e9UaRA@mail.gmail.com/
Suggested-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Link: https://patch.msgid.link/20260126062158.308598-3-slark_xiao@163.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/wwan/wwan_core.c