From nobody Tue Feb 10 09:57:23 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) (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 07DC231282C; Wed, 31 Dec 2025 06:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767163950; cv=none; b=rGk9BvnlN+0wTLgL+5n6cr8mmsJDaLRuVoAbukpR8lY70G14FBM3jfkL18P0ft/wlcEa71gdqyJaQclCNypOkk8eVrBVPZQjRawru7FgPH6Eux795skae/qfsg1ST4NHi9sLht4GtENMKdCOFPBUv4KSRoSSmmgoitYu/7gmHy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767163950; c=relaxed/simple; bh=uwBpo1F6QPiu3cqG/KphpIXDyG1I93Ps81dd1bruFEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e0aXOLqOU2jdAp+xK/QaE65Xs+ZNHol4P3V5RYqt7JlcFwwoxM6H+J4mxoOCtmeCYiQrDa8X0Oy0VWnoL7N7Bi4RXU1/B+1ITjMG3zTr0IrAIni1q+Ath6wDOiWx/qAcZzjpY3qUz470OZqJZNONHtP/J5AFYSjzBHYRg4HKBv4= 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=d0ZCwGRM; arc=none smtp.client-ip=220.197.31.3 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="d0ZCwGRM" 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=d0ZCwGRMIQuhTbDDk2 psoDR6PYPskuw9PPk67yZWhcMfaErLMdBEZRa66FrF4sbkI7Vuugp3+jd9GFnicX QHnjElc2oeEYzvV+NlhwSagmVLOYo6pAvQ8DmDvhF9c7aDbaRdGwr9ttJdOgLYK/ CeVNdtr2wVFUdgMH+df0AX8iE= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wDHpCPmx1Rp9FyCDg--.29927S4; Wed, 31 Dec 2025 14:51:34 +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 v3 2/8] net: wwan: core: split port creation and registration Date: Wed, 31 Dec 2025 14:51:03 +0800 Message-Id: <20251231065109.43378-3-slark_xiao@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251231065109.43378-1-slark_xiao@163.com> References: <20251231065109.43378-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: _____wDHpCPmx1Rp9FyCDg--.29927S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxJFWkAw45CFWxKFW5Jw1xuFg_yoWrCFWUp3 W0gas3tFW8Jr13ur43AF47ZFWF9a1Ika4SyrW8W34Skrn0qryFvFZY9FyqvrWrGFy7GFy3 XF45ta10k3WUGr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jT1v3UUUUU= X-CM-SenderInfo: xvod2y5b0lt0i6rwjhhfrp/xtbCwBaeA2lUx-aq5QAA3I 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