🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26251

Re: [PATCH net-next v14 4/6] net: wwan: t9xx: Add control port

#26251
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 09:46
175 lines
13616 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] mtk_port_alloc_and_add() (drivers/net/wwan/t9xx/mtk_port.c)
  inserts the kzalloc()'ed port into port_mngr->port_tbl[] with…
- [Low] mtk_port_internal_close() (drivers/net/wwan/t9xx/mtk_port_io.c)
  clears PORT_S_OPEN with test_and_clear_bit() before…

--

net: wwan: t9xx: Add control port

This adds the t9xx port I/O layer and the port manager. Together they
create and manage the control ports and pass TRBs between the ports and
CLDMA. The patch also gives struct trb a kref, so the TRB handler holds a
reference while it dispatches, and it stamps the TX sequence number at
hardware hand-off.

> diff --git a/drivers/net/wwan/t9xx/mtk_port.c b/drivers/net/wwan/t9xx/mtk_port.c
> new file mode 100644
> index 0000000000000..95b8ba4993cdc
> --- /dev/null
> +++ b/drivers/net/wwan/t9xx/mtk_port.c

[ ... ]

> +static struct mtk_port *mtk_port_alloc_and_add(struct mtk_port_mngr *port_mngr,
> +					       const struct mtk_port_cfg *dflt_info)
> +{
> +	struct mtk_port *port;
> +	int ret;
> +
> +	port = kzalloc_obj(*port, GFP_KERNEL);
> +	if (!port) {
> +		ret = -ENOMEM;
> +		goto err_alloc_port;
> +	}
> +	memcpy(&port->info, dflt_info, sizeof(*dflt_info));
> +
> +	ret = mtk_port_tbl_add(port_mngr, port);
> +	if (ret < 0) {
> +		dev_err(port_mngr->ctrl_blk->mdev->dev,
> +			"Failed to add port(%s) to port tbl\n", dflt_info->name);
> +		goto err_free_port;
> +	}
> +
> +	port->port_mngr = port_mngr;
> +	ret = mtk_port_get_ops(port->info.type)->init(port);
> +	if (ret < 0) {
> +		mtk_port_tbl_del(port_mngr, port);
> +		goto err_free_port;
> +	}

[Severity: Low]
This isn't a bug, but should the port be fully set up before it goes
into port_tbl[]?

mtk_port_tbl_add() publishes the port with xa_insert() before
port->port_mngr is set. It also runs before ->init() calls
mtk_port_struct_init():

mtk_port_struct_init() {
	clear_bit(PORT_S_ENABLE, &port->status);
	kref_init(&port->kref);
	init_waitqueue_head(&port->trb_wq);
}

Suppose a lookup such as mtk_port_get_by_name() found the port in this
window. It would kref_get() a zero refcount, and the port would still
have a NULL port->port_mngr. On ->init() failure the port is also freed
with a plain kfree() after xa_erase().

As far as I can tell, this cannot happen in the current series:

- mtk_port_mngr_init() sets ctrl_blk->port_mngr only after
  mtk_port_tbl_create() returns.
- Every reader gets port_mngr either from ctrl_blk->port_mngr or from a
  port that is already in the table.
- Every ->init() returns 0, so the kfree() on init failure never runs.

Would it still be clearer to set port->port_mngr and call ->init() before
mtk_port_tbl_add(), so the ordering no longer depends on those
conditions?

[ ... ]

> diff --git a/drivers/net/wwan/t9xx/mtk_port_io.c b/drivers/net/wwan/t9xx/mtk_port_io.c
> new file mode 100644
> index 0000000000000..392d2ae54ef55
> --- /dev/null
> +++ b/drivers/net/wwan/t9xx/mtk_port_io.c

[ ... ]

> +static int mtk_port_common_open(struct mtk_port *port)
> +{
> +	int ret = 0;
> +
> +	if (!test_bit(PORT_S_ENABLE, &port->status))
> +		return -ENODEV;
> +
> +	if (test_and_set_bit(PORT_S_OPEN, &port->status))
> +		return -EBUSY;
> +
> +	clear_bit(PORT_S_FLUSH, &port->status);
> +
> +	return ret;
> +}
> +
> +static void mtk_port_common_close(struct mtk_port *port)
> +{
> +	set_bit(PORT_S_FLUSH, &port->status);
> +	wake_up_all(&port->trb_wq);
> +}

[ ... ]

> +int mtk_port_internal_close(struct mtk_port *port)
> +{
> +	int ret = 0;
> +
> +	if (!port) {
> +		ret = -EINVAL;
> +		goto end;
> +	}
> +
> +	/* Claim the close: a second caller must not drop the reference again. */
> +	if (!test_and_clear_bit(PORT_S_OPEN, &port->status)) {
> +		pr_err("Port(%s) has been closed\n", port->info.name);
> +		ret = -EBADF;
> +		goto end;
> +	}
> +
> +	mtk_port_common_close(port);

[Severity: Low]
Could an open run between the clear of PORT_S_OPEN and the set of
PORT_S_FLUSH here?

If mtk_port_common_open() ran in that window, the order would be:

close: test_and_clear_bit(PORT_S_OPEN)
open:  test_and_set_bit(PORT_S_OPEN)
open:  clear_bit(PORT_S_FLUSH)
close: mtk_port_common_close()->set_bit(PORT_S_FLUSH)

The port would then have both PORT_S_OPEN and PORT_S_FLUSH set.
mtk_port_status_check() would fail every write with -EBADF until the
port is closed again.

This doesn't look reachable in the series:

- The internal ports are opened and closed only from
  mtk_fsm_ctrl_ch_start() and mtk_fsm_ctrl_ch_stop().
- Both run in the single FSM kthread.
- mtk_fsm_stop() joins that thread with kthread_stop() before it calls
  mtk_fsm_ctrl_ch_stop() itself.
- The WWAN ports added later in the series do the same steps under
  port->w_priv.w_lock.

The comment above enum mtk_port_status says callers serialise ->enable(),
->disable() and open of a port. Should it mention close as well, since
this sequence also depends on that?

> +	mtk_port_put_locked(port);
> +end:
> +	return ret;
> +}

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-t9xx_driver_v1-v14-0-08ebc870ea94%40compal.com
Technical Details
Message-ID: <179629119999.3146.8573557356536424800@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376452-linux-kernel-netdev=dewy.ru
References: <20261202-t9xx_driver_v1-v14-4-08ebc870ea94@compal.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376452-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v14 4/6] net: wwan: t9xx: Add control port
Date: Thu, 03 Dec 2026 09:46:39 +0000
Organization: Usenet Network
Message-ID: <179629119999.3146.8573557356536424800@kernel.org>
References: <20261202-t9xx_driver_v1-v14-4-08ebc870ea94@compal.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2451553"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:8wqVRBVif3SGvQfZjXPGeitUIlo= sha256:NLc0ndFb8TLub7pz122KNQDYrtEMrR0s4XZgCTubgXs=
	sha1:K5bPMaRf5nAdS9cOhoHZROyGwt0= sha256:oeBjhvAJFHXeAfmcgg2ucCkx/ybH4O16VWe6npv5a44=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id B2A22117880; Thu,  3 Dec 2026 12:47:00 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id GTyKTNzoKulQ;
	Thu,  3 Dec 2026 12:46:57 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376452-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 2C9AA1178AE; Thu,  3 Dec 2026 12:46:48 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 8F9E826C44; Thu,  3 Dec 2026 09:46:44 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796291202;
	b=lzZ7aGBX41ModvNR/qI4v+XglT0QPVl/5R5ERDlWKFrOYXKq23fM3BzgL7krUjFBPtBp
	 xbTFfGv7cRio2LnmMQ7UIZ5+42mpeJ3b9gmByDPPGg3Y0Ji1RrB6ARDUx05FwrIxAV8Gh
	 6kZO79CI71nwu0JD8J7KPU1RW3rQgpHiBkwolWp/n6QCrX9tY1HR0xWbtNkS8O+/b4A0u
	 TezzBRLogBstDSJ3qcg6hjwCkCqeypUkZDG5fA4Vb5K9O7b1msCD6OtAom0HFs1HpVcZJ
	 Xg3o1muOL0Z6Tgn4vj5XINyqjKklmBF/sNHyP8qGwIA7DvOpKsvkpiuXUFAaz8vkYxQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796291202;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=wIu5oaCPpgSnkfGoZOVfQ8JxdG6q8hd2U1tpIGca7sQ=;
	b=wDP+edAW28abRLJRRv8qjQWgMTXRlPBeaa9OybZpsamp1kAw8B2Q6hsKWuYhbJuidAYA
	 NaBZlRVZcPobdwYazC/hbsbzkrwdmb8w8Y/IJv3S/WJd1WZnWurHT6U1mjIRBb5bnhmhj
	 wo/0QOgQqfG0u7ZKLLRT87Y1VVY4tNA5EXGsn1zS3zt6Nuj9/thzNyEJa1zoexmke2/qH
	 s0gUntleIORa/Z79hIy5sgI1ezfrWcTBoDWCxUwg0AC/RshTNAHN4ClQ30B2+GKwmDT9w
	 JmMujgIxBsXUVjGPu40HCcNq5pFHy2FG7gSAqfAaZXE2+OfWuWaYGPrw2+bSUcqIhhQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AN3W+MbZ;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 94FF1606A688;
	Thu,  3 Dec 2026 09:46:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AN3W+MbZ
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796291201;
	b=NU7rZfQ+5nl/G8fIHxDBmPbNy+WXzEaBr6gVUNapF7//xxC33WnlEPa5bgazbiJ65WcE
	 +bLcrxGC5Cd2YVhvQZHUS9JAw/o4v3lle70mWw3ZPnVTOHCfjFdzGIL/P1znaYtKXVP3e
	 BgcxmmA4i1pfEg6gwSc66JcyzmEOxrGZ3p7c8IuUPFAXFqginl1QrrmlzT7ru2hOjUXmL
	 Wb4kREq4klaa4EEvVX58DhygnM86wgtjk93dD4YfA7cqGXtVWLHGQaxXZuQquzP8lW261
	 IyKLIH5KAQHHjsnwIO38o2FqXSEDk2+fO9ONiv7r5FD6Fn2OjHqeYJciQDARwQ+3Zng==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796291201;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=wIu5oaCPpgSnkfGoZOVfQ8JxdG6q8hd2U1tpIGca7sQ=;
	b=2fXJz6jbV8s0JzqNXzKc0JcD3AHhDPr+4izrPiWDsPSyNl2iKkKz3OCMGF1lQpZR8s7+
	 jYZJn2uMoxnm1BQ+thX9i8WbYNFV9sJyN8sOI552v+8k0AqsWZWXsXZYq5Jo2uBEE1AEQ
	 mpjSF+44KR8GS4pVi20MOkqanQeiOHRBG0dYTuMWZ04QaS16becBNcZqq5msQCeKuo+QD
	 vV9RlP1uF0R6BHrE/D72Zhaaypg1gjhHowaqsLIj5c2IMXQzWsK8SxphKs6ueTornId15
	 kvuBmshobFkF44DCZHQiz8OGhILaZD9Az5WvLPOePCu33g5v1g1dRfNVe5CV1Gpbiwg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AN3W+MbZ;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6A36606A68F;
	Thu,  3 Dec 2026 09:46:41 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 649491F0089B;
	Thu,  3 Dec 2026 09:46:40 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796291201;
	bh=wIu5oaCPpgSnkfGoZOVfQ8JxdG6q8hd2U1tpIGca7sQ=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=AN3W+MbZXm3DxUasqJj7DwscAajs5u9GSu9R2Rry27xXwOZHG04EG9/xH7NXeL+R6
	 sLJ3SyGA8+eMCufV0Xi3bXjWx6LWMB0HVK4lFZAZerexKoFFuBf8u2x91brQ1c0wJM
	 CCZcCXNeAwFFtIJB4kkKrDfghSJIee9Iw64iAm1l+VOqhFXJlTP/sLVRKfmGXVIT8u
	 Hs567tm4Ve7HDX+J0IMLcc0+06dLx6RJTUQCs2NjB4YWDChsQOl61oK6k7VepzGNwY
	 aK3GbqKwwjMkzcjB/4vqvD5Vq62RXQulSTxw3GaHe2s7uqJaadAQQLmAKAngd260xP
	 WiRezW54QA7QQ==
X-Cc: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com,
 johannes@sipsolutions.net, andrew+netdev@lunn.ch, davem@davemloft.net,
 kuba@kernel.org, pabeni@redhat.com, wen-zhi.huang@mediatek.com,
 shi-wei.yeh@mediatek.com, Minano.tseng@mediatek.com, matthias.bgg@gmail.com,
 angelogioacchino.delregno@collabora.com, horms@kernel.org, corbet@lwn.net,
 skhan@linuxfoundation.org, robert_yu@compal.com, Jeff_Chang@compal.com,
 edumazet@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
 linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org,
 linux-doc@vger.kernel.org
X-In-Reply-To: <20261202-t9xx_driver_v1-v14-4-08ebc870ea94@compal.com>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list