Re: [net-next v4 7/8] net: wwan: prevent premature device unregister when NMEA port is present

From: Sergey Ryazanov

Date: Tue Jan 06 2026 - 20:05:55 EST


Hi Slark, Loic,

sorry for late joining the discussion, please find a design question below.

On 1/5/26 12:20, Slark Xiao wrote:
From: Loic Poulain <loic.poulain@xxxxxxxxxxxxxxxx>

The WWAN core unregisters the device when it has no remaining WWAN ops
or child devices. For NMEA port types, the child is registered under
the GNSS class instead of WWAN, so the core incorrectly assumes there
are no children and unregisters the WWAN device too early. This leads
to a second unregister attempt after the NMEA device is removed.

To fix this issue, we register a virtual WWAN port device along the
GNSS device, this ensures the WWAN device remains registered until
all associated ports, including NMEA, are properly removed.

wwan core assumes whole responsibility for managing a WWAN device. We already use wwan_create_dev()/wwan_remove_dev() everywhere. But, we are checking the reminding references in an implicit way using device_for_each_child() and registered OPS existence. Thus, we need this trick with a virtual child port.

Does it make sense to switch to an explicit reference counting? We can introduce such counter to the wwan_device structure, and increment/decrement it on every wwan_create_dev()/wwan_remove_dev() call. So, we will do device_unregister() upon reference number becoming zero.

If it sounds promising, I can send a RFC, let's say, tomorrow.

--
Sergey