Re:Re: [net-next v4 7/8] net: wwan: prevent premature device unregister when NMEA port is present
From: Slark Xiao
Date: Wed Jan 07 2026 - 02:30:41 EST
At 2026-01-07 09:06:05, "Sergey Ryazanov" <ryazanov.s.a@xxxxxxxxx> wrote:
>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.
The RFC only for this patch or the existing design? Since there is problem
reported in https://patchwork.kernel.org/project/netdevbpf/patch/20260105102018.62731-3-slark_xiao@xxxxxxx/#26720828.
Currently design:
minor = ida_alloc_range(&minors, 0, WWAN_MAX_MINORS - 1, GFP_KERNEL);
if (minor < 0)
return minor;
port->dev.class = &wwan_class;
// when cdev is false, no devt was assigned. But wwan_port_destroy() use devt to free
if (cdev)
port->dev.devt = MKDEV(wwan_major, minor);
We need to have a update based on this patch if we want to use this one in this serial.