From: "Slark Xiao" <slark_xiao@163.com>
To: "Jakub Kicinski" <kuba@kernel.org>,
"Sergey Ryazanov" <ryazanov.s.a@gmail.com>
Cc: quic_qianyu@quicinc.com, davem@davemloft.net,
loic.poulain@oss.qualcomm.com, johannes@sipsolutions.net,
netdev@vger.kernel.org, zaihan@unrealasia.net, johan@kernel.org,
andrew+netdev@lunn.ch, edumazet@google.com,
linux-kernel@vger.kernel.org, dnlplm@gmail.com,
manivannan.sadhasivam@linaro.org, pabeni@redhat.com,
mani@kernel.org
Subject: Re:Re:Re: [net-next,v7,3/8] net: wwan: core: split port creation and registration
Date: Thu, 22 Jan 2026 10:31:55 +0800 (CST) [thread overview]
Message-ID: <22e8939e.239f.19be38b4aa0.Coremail.slark_xiao@163.com> (raw)
In-Reply-To: <55195fd2.3367.19bc4d5a71f.Coremail.slark_xiao@163.com>
At 2026-01-16 11:24:54, "Slark Xiao" <slark_xiao@163.com> wrote:
>
>
>At 2026-01-16 10:44:35, "Jakub Kicinski" <kuba@kernel.org> wrote:
>>This is an AI-generated review of your patch. The human sending this
>>email has considered the AI review valid, or at least plausible.
>>
>>For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
>>---
>>net: wwan: core: split port creation and registration
>>
>>This patch splits the port creation function to prepare for upcoming GNSS
>>port type support. It separates device_register() into device_initialize()
>>and device_add(), and moves minor number allocation into the new
>>wwan_port_register_wwan() function.
>>
>>> diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c
>>> index 1da935e84008..1a9a77d597e6 100644
>>> --- a/drivers/net/wwan/wwan_core.c
>>> +++ b/drivers/net/wwan/wwan_core.c
>>> @@ -357,7 +357,8 @@ static void wwan_port_destroy(struct device *dev)
>>> {
>>> struct wwan_port *port = to_wwan_port(dev);
>>>
>>> - ida_free(&minors, MINOR(port->dev.devt));
>>> + if (dev->class == &wwan_class)
>>> + ida_free(&minors, MINOR(dev->devt));
>>> mutex_destroy(&port->data_lock);
>>> mutex_destroy(&port->ops_lock);
>>> kfree(port);
>>
>>[ ... ]
>>
>>> +/* Register a regular WWAN port device (e.g. AT, MBIM, etc.) */
>>> +static int wwan_port_register_wwan(struct wwan_port *port)
>>> +{
>>> + struct wwan_device *wwandev = to_wwan_dev(port->dev.parent);
>>> + char namefmt[0x20];
>>> + int minor, err;
>>> +
>>> + /* A port is exposed as character device, get a minor */
>>> + minor = ida_alloc_range(&minors, 0, WWAN_MAX_MINORS - 1, GFP_KERNEL);
>>> + if (minor < 0)
>>> + return minor;
>>> +
>>> + port->dev.class = &wwan_class;
>>> + port->dev.devt = MKDEV(wwan_major, minor);
>>
>>[ ... ]
>>
>>> + err = device_add(&port->dev);
>>> +
>>> + mutex_unlock(&wwan_register_lock);
>>> +
>>> + if (err) {
>>> + ida_free(&minors, minor);
>> ^^^^^^^^^^^^^^^^^^^^^^^^
>>
Hi Sergey,
Can we modify it like this?
+ if (err) {
+ ida_free(&minors, minor);
+ port->dev.class = NULL;
This shall be able to avoid the double free issue.
>>When device_add() fails, this frees the minor. However, port->dev.class
>>was already set to wwan_class above, and port->dev.devt contains the minor
>>number. The caller (wwan_create_port) then calls put_device() which
>>triggers wwan_port_destroy(). Since dev->class == &wwan_class is true,
>>wwan_port_destroy() calls ida_free() again on the same minor.
>>
>>Wouldn't this cause a double ida_free when device_add() fails? The call
>>chain is: wwan_port_register_wwan() fails -> ida_free(minor) -> return
>>error -> wwan_create_port() -> put_device() -> wwan_port_destroy() ->
>>ida_free(minor) again.
>>
>>Maybe the class should be cleared on error before returning, or the
>>ida_free in the error path should be removed since wwan_port_destroy()
>>will handle it?
>>
>Hi Sergey,
>We need to review this changes again.
>
>>> + return err;
>>> + }
>>> +
>>> + dev_info(&wwandev->dev, "port %s attached\n", dev_name(&port->dev));
>>> +
>>> + return 0;
>>> +}
>>
>>[ ... ]
>>
>>> + device_initialize(&port->dev);
>>> +
>>> + err = wwan_port_register_wwan(port);
>>> if (err)
>>> goto error_put_device;
>>> +
>>> return port;
>>>
>>> error_put_device:
>>> + put_device(&port->dev);
>>--
>>pw-bot: cr
next prev parent reply other threads:[~2026-01-22 2:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 11:46 [net-next v7 0/8] net: wwan: add NMEA port type support Slark Xiao
2026-01-15 11:46 ` [net-next v7 1/8] net: wwan: core: remove unused port_id field Slark Xiao
2026-01-15 11:46 ` [net-next v7 2/8] net: wwan: core: explicit WWAN device reference counting Slark Xiao
2026-01-15 11:46 ` [net-next v7 3/8] net: wwan: core: split port creation and registration Slark Xiao
2026-01-16 2:44 ` [net-next,v7,3/8] " Jakub Kicinski
2026-01-16 3:24 ` Slark Xiao
2026-01-22 2:31 ` Slark Xiao [this message]
2026-01-22 12:01 ` Loic Poulain
2026-01-15 11:46 ` [net-next v7 4/8] net: wwan: core: split port unregister and stop Slark Xiao
2026-01-15 11:46 ` [net-next v7 5/8] net: wwan: add NMEA port support Slark Xiao
2026-01-20 12:30 ` Simon Horman
2026-01-21 2:08 ` Slark Xiao
2026-01-21 14:16 ` Loic Poulain
2026-01-21 16:53 ` Simon Horman
2026-01-15 11:46 ` [net-next v7 6/8] net: wwan: hwsim: refactor to support more port types Slark Xiao
2026-01-15 11:46 ` [net-next v7 7/8] net: wwan: hwsim: support NMEA port emulation Slark Xiao
2026-01-16 2:44 ` [net-next,v7,7/8] " Jakub Kicinski
2026-01-22 3:06 ` Slark Xiao
2026-01-15 11:46 ` [net-next v7 8/8] net: wwan: mhi_wwan_ctrl: Add NMEA channel support Slark Xiao
2026-01-15 20:19 ` Sergey Ryazanov
2026-01-16 2:43 ` [net-next v7 0/8] net: wwan: add NMEA port type support Jakub Kicinski
2026-01-16 3:18 ` Slark Xiao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=22e8939e.239f.19be38b4aa0.Coremail.slark_xiao@163.com \
--to=slark_xiao@163.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dnlplm@gmail.com \
--cc=edumazet@google.com \
--cc=johan@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loic.poulain@oss.qualcomm.com \
--cc=mani@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quic_qianyu@quicinc.com \
--cc=ryazanov.s.a@gmail.com \
--cc=zaihan@unrealasia.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox