Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: kyle.switch@motor-comm.com
Cc: andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	mmyangfl@gmail.com, horms@kernel.org, linux@armlinux.org.uk,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, david.laight.linux@gmail.com,
	ming.xu@motor-comm.com, xiaolin.xu@motor-comm.com,
	jianmin.wang@motor-comm.com, wei.zhang@gl-inet.com,
	sijia.huang@gl-inet.com
Subject: Re: [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking
Date: Thu, 03 Dec 2026 08:57:28 +0000	[thread overview]
Message-ID: <179628824852.3146.765398832831553826@kernel.org> (raw)
In-Reply-To: <20261202084022.3716891-3-kyle.switch@motor-comm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] yt921x_mbus_int_init() in drivers/net/dsa/motorcomm/mdio_bus.c
  leaks the mii_bus on the new max_ports error path.
- [Low] The commit message says the patch will "Validate max_ports
  against the size of priv->ports (and the u32 width of phy_mask) before…

--

net: dsa: motorcomm: use max_ports in series for port bounds checking

This commit replaces the hardcoded YT921X_PORT_NUM with the per-series
max_ports field. The field is now used in the internal MDIO bus read and
write bounds checks and in the phy_mask setup in yt921x_mbus_int_init().
It also adds a validation of max_ports before it is used in GENMASK().

> Validate max_ports against the size of priv->ports (and the u32
> width of phy_mask) before using it in GENMASK().

[Severity: Low]
Does the code in yt921x_mbus_int_init() actually check the u32 width of
phy_mask? The only check is:

    if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) {

Nothing compares max_ports against 32 or BITS_PER_TYPE(u32). There is
also no static_assert() or BUILD_BUG_ON() that ties
ARRAY_SIZE(priv->ports) to the width of mbus->phy_mask.

The u32 bound only holds because struct yt921x_priv still declares:

    struct yt921x_port ports[YT921X_PORT_NUM];

If priv->ports ever grew past 32 entries, GENMASK(max_ports - 1, 0) would
get an out-of-range shift that this check would not catch.

The commit message also says this "removes family-specific constants from
the common code path". The new bound is still YT921X_PORT_NUM through
ARRAY_SIZE(priv->ports), so a family with more than 11 ports would be
rejected rather than supported.

Could the message be reworded, or an explicit check be added for the u32
width?

> diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c
> index a4062e6b0f000..a06e2cc94a3e2 100644
> --- a/drivers/net/dsa/motorcomm/mdio_bus.c
> +++ b/drivers/net/dsa/motorcomm/mdio_bus.c

[ ... ]

> @@ -155,6 +155,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
>  {
>  	struct device *dev = yt921x_priv_to_device(priv);
>  	struct mii_bus *mbus;
> +	u32 max_ports;
>  	int res;
>
>  	mbus = mdiobus_alloc();
> @@ -167,7 +168,12 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
>  	mbus->read = yt921x_mbus_int_read;
>  	mbus->write = yt921x_mbus_int_write;
>  	mbus->parent = dev;
> -	mbus->phy_mask = (u32)~GENMASK(YT921X_PORT_NUM - 1, 0);
> +	max_ports = priv->series->max_ports;
> +	if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) {
> +		dev_err(dev, "Invalid max_ports: %u\n", max_ports);
> +		return -EINVAL;
                ^^^^

[Severity: Medium]
Does this early return leak the mii_bus allocated by mdiobus_alloc() just
above?

mdiobus_alloc() is not devm-managed. priv->mbus_int is only set on
success, so the caller has no pointer it could free:

drivers/net/dsa/motorcomm/chip.c:yt921x_dsa_setup() {
    ...
		res = yt921x_mbus_int_init(priv, child);
		of_node_put(child);
		if (res)
			return res;
    ...
}

The of_mdiobus_register() failure path later in the same function does
call mdiobus_free(mbus) before returning.

The leak is also still there after the later patch in this series, "net:
dsa: motorcomm: use GENMASK_U32() for mbus phy_mask". That patch only
changes the phy_mask line.

Could the max_ports check be moved before mdiobus_alloc()? Alternatively,
mdiobus_free(mbus) could be called before returning -EINVAL.

> +	}
> +	mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0);
>
>  	res = of_mdiobus_register(mbus, mnp);
>  	if (res) {

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com

  reply	other threads:[~2026-12-03  8:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch
2026-12-02  8:40 ` [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid Kyle Switch
2026-12-03  8:57   ` netdev-bot+sashiko
2026-12-02  8:40 ` [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Kyle Switch
2026-12-03  8:57   ` netdev-bot+sashiko [this message]
2026-12-02  8:40 ` [PATCH net-next v18 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask Kyle Switch
2026-12-03  8:57   ` netdev-bot+sashiko
2026-12-02  8:40 ` [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 Kyle Switch
2026-12-02 22:58   ` Rob Herring (Arm)
2026-12-03  8:57   ` netdev-bot+sashiko
2026-12-02  8:40 ` [PATCH net-next v18 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags Kyle Switch
2026-12-03  8:57   ` netdev-bot+sashiko
2026-12-02  8:40 ` [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x Kyle Switch
2026-12-03  8:57   ` 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=179628824852.3146.765398832831553826@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jianmin.wang@motor-comm.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kyle.switch@motor-comm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=ming.xu@motor-comm.com \
    --cc=mmyangfl@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=sijia.huang@gl-inet.com \
    --cc=wei.zhang@gl-inet.com \
    --cc=xiaolin.xu@motor-comm.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