From nobody Tue Feb 10 06:27:18 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFBD82F25EF; Mon, 5 Jan 2026 10:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767608491; cv=none; b=Nktt3LEkfJ9oqCOwp38zuCOqb9rx77AUP2rlVyjpcJDDLwM3+uNACtk//3IkFOhmtSoHuOVNuYf5LjaId6rzMkvtwBT5fpRagdremyB7MYs/m97ENe/cwFz7YmCSYUdVTl3KXJ+kd+5aad7elm2Uz7acCnDKQKUUvQ5Sk+Fg778= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767608491; c=relaxed/simple; bh=uwBpo1F6QPiu3cqG/KphpIXDyG1I93Ps81dd1bruFEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SYLMM9r5fnpPPiADCX/48F6/MkSYEV0qWzIKUO9gsgiCkqoOy9DtP6RpqUBmwZw5FdNQQ7ki2xrWTuFEIS7j94Ae9gmMaKBGz1buVFgpI8n45oc42xlPHdk5pO1mO6cPhrmQ27I/DEBhFXWkxBtbO2kGa6bLw3rTnbaApjGleEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=k0yYMaZU; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="k0yYMaZU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Rp Tbb2gLO4QJQ+S7G8iNjUbiqTtKOf3krgXz6hII5WY=; b=k0yYMaZUaBtdNc+KEW YZg80g5qxPmMPhtNRAfm10AhHX1WhWZxSHZQbdsM8W33NOKLcjh2cEH1UKjwB4Ww UVPTkiPF6Ddetfq1ija6TMN5tUGtpG80IDvasrKOkW6x3iIHvU/E8CDdAlXuxZz8 GHK7VCI6NJSKb8WK6iTlCwdZk= Received: from localhost.localdomain (unknown []) by gzsmtp3 (Coremail) with SMTP id PigvCgDnrxNrkFtpVWA8KQ--.198S4; Mon, 05 Jan 2026 18:20:44 +0800 (CST) From: Slark Xiao To: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com, johannes@sipsolutions.net, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mani@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next v4 2/8] net: wwan: core: split port creation and registration Date: Mon, 5 Jan 2026 18:20:12 +0800 Message-Id: <20260105102018.62731-3-slark_xiao@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260105102018.62731-1-slark_xiao@163.com> References: <20260105102018.62731-1-slark_xiao@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PigvCgDnrxNrkFtpVWA8KQ--.198S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxJFWkAw45CFWxKFW5Jw1xuFg_yoWrCFWUp3 W0gas3tFW8Jr13ur43AF47ZFWF9a1Ika4SyrW8W34Skrn0qryFvFZY9FyqvrWrGFy7GFy3 XF45ta10k3WUGr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2jgxUUUUU= X-CM-SenderInfo: xvod2y5b0lt0i6rwjhhfrp/xtbC5xx02GlbkHwS3AAA3H Content-Type: text/plain; charset="utf-8" From: Sergey Ryazanov Upcoming GNSS (NMEA) port type support requires exporting it via the GNSS subsystem. On another hand, we still need to do basic WWAN core work: find or allocate the WWAN device, make it the port parent, etc. To reuse as much code as possible, split the port creation function into the registration of a regular WWAN port device, and basic port struct initialization. To be able to use put_device() uniformly, break the device_register() call into device_initialize() and device_add() and call device initialization earlier. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 66 ++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index ade8bbffc93e..edee5ff48f28 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -361,7 +361,8 @@ static void wwan_port_destroy(struct device *dev) { struct wwan_port *port =3D to_wwan_port(dev); =20 - ida_free(&minors, MINOR(port->dev.devt)); + if (dev->class =3D=3D &wwan_class) + ida_free(&minors, MINOR(dev->devt)); mutex_destroy(&port->data_lock); mutex_destroy(&port->ops_lock); kfree(port); @@ -440,6 +441,41 @@ static int __wwan_port_dev_assign_name(struct wwan_por= t *port, const char *fmt) return dev_set_name(&port->dev, "%s", buf); } =20 +/* 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 =3D to_wwan_dev(port->dev.parent); + char namefmt[0x20]; + int minor, err; + + /* A port is exposed as character device, get a minor */ + minor =3D ida_alloc_range(&minors, 0, WWAN_MAX_MINORS - 1, GFP_KERNEL); + if (minor < 0) + return minor; + + port->dev.class =3D &wwan_class; + port->dev.devt =3D MKDEV(wwan_major, minor); + + /* allocate unique name based on wwan device id, port type and number */ + snprintf(namefmt, sizeof(namefmt), "wwan%u%s%%d", wwandev->id, + wwan_port_types[port->type].devsuf); + + /* Serialize ports registration */ + mutex_lock(&wwan_register_lock); + + __wwan_port_dev_assign_name(port, namefmt); + err =3D device_add(&port->dev); + + mutex_unlock(&wwan_register_lock); + + if (err) + return err; + + dev_info(&wwandev->dev, "port %s attached\n", dev_name(&port->dev)); + + return 0; +} + struct wwan_port *wwan_create_port(struct device *parent, enum wwan_port_type type, const struct wwan_port_ops *ops, @@ -448,8 +484,7 @@ struct wwan_port *wwan_create_port(struct device *paren= t, { struct wwan_device *wwandev; struct wwan_port *port; - char namefmt[0x20]; - int minor, err; + int err; =20 if (type > WWAN_PORT_MAX || !ops) return ERR_PTR(-EINVAL); @@ -461,17 +496,9 @@ struct wwan_port *wwan_create_port(struct device *pare= nt, if (IS_ERR(wwandev)) return ERR_CAST(wwandev); =20 - /* A port is exposed as character device, get a minor */ - minor =3D ida_alloc_range(&minors, 0, WWAN_MAX_MINORS - 1, GFP_KERNEL); - if (minor < 0) { - err =3D minor; - goto error_wwandev_remove; - } - port =3D kzalloc(sizeof(*port), GFP_KERNEL); if (!port) { err =3D -ENOMEM; - ida_free(&minors, minor); goto error_wwandev_remove; } =20 @@ -485,27 +512,14 @@ struct wwan_port *wwan_create_port(struct device *par= ent, mutex_init(&port->data_lock); =20 port->dev.parent =3D &wwandev->dev; - port->dev.class =3D &wwan_class; port->dev.type =3D &wwan_port_dev_type; - port->dev.devt =3D MKDEV(wwan_major, minor); dev_set_drvdata(&port->dev, drvdata); + device_initialize(&port->dev); =20 - /* allocate unique name based on wwan device id, port type and number */ - snprintf(namefmt, sizeof(namefmt), "wwan%u%s%%d", wwandev->id, - wwan_port_types[port->type].devsuf); - - /* Serialize ports registration */ - mutex_lock(&wwan_register_lock); - - __wwan_port_dev_assign_name(port, namefmt); - err =3D device_register(&port->dev); - - mutex_unlock(&wwan_register_lock); - + err =3D wwan_port_register_wwan(port); if (err) goto error_put_device; =20 - dev_info(&wwandev->dev, "port %s attached\n", dev_name(&port->dev)); return port; =20 error_put_device: --=20 2.25.1