From: netdev-bot+sashiko@kernel.org
To: jackbb_wu@compal.com
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
Subject: Re: [PATCH net-next v14 4/6] net: wwan: t9xx: Add control port
Date: Thu, 03 Dec 2026 09:46:39 +0000 [thread overview]
Message-ID: <179629119999.3146.8573557356536424800@kernel.org> (raw)
In-Reply-To: <20261202-t9xx_driver_v1-v14-4-08ebc870ea94@compal.com>
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
next prev parent reply other threads:[~2026-12-03 9:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 8:58 [PATCH net-next v14 0/6] net: wwan: t9xx: Add MediaTek T9XX WWAN driver Jack Wu via B4 Relay
2026-12-02 8:59 ` [PATCH net-next v14 1/6] net: wwan: t9xx: Add PCIe core Jack Wu via B4 Relay
2026-12-03 9:46 ` netdev-bot+sashiko
2026-12-02 8:59 ` [PATCH net-next v14 2/6] net: wwan: t9xx: Add control plane transaction layer framework Jack Wu via B4 Relay
2026-12-02 8:59 ` [PATCH net-next v14 3/6] net: wwan: t9xx: Add control DMA interface Jack Wu via B4 Relay
2026-12-03 9:46 ` netdev-bot+sashiko
2026-12-02 8:59 ` [PATCH net-next v14 4/6] net: wwan: t9xx: Add control port Jack Wu via B4 Relay
2026-12-03 9:46 ` netdev-bot+sashiko [this message]
2026-12-02 8:59 ` [PATCH net-next v14 5/6] net: wwan: t9xx: Add FSM thread Jack Wu via B4 Relay
2026-12-03 9:46 ` netdev-bot+sashiko
2026-12-02 8:59 ` [PATCH net-next v14 6/6] net: wwan: t9xx: Add AT & MBIM WWAN ports Jack Wu via B4 Relay
2026-12-03 9:46 ` netdev-bot+sashiko
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=179629119999.3146.8573557356536424800@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=Jeff_Chang@compal.com \
--cc=Minano.tseng@mediatek.com \
--cc=andrew+netdev@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jackbb_wu@compal.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=loic.poulain@oss.qualcomm.com \
--cc=matthias.bgg@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=robert_yu@compal.com \
--cc=ryazanov.s.a@gmail.com \
--cc=shi-wei.yeh@mediatek.com \
--cc=skhan@linuxfoundation.org \
--cc=wen-zhi.huang@mediatek.com \
/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