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 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask
Date: Thu, 03 Dec 2026 08:57:30 +0000 [thread overview]
Message-ID: <179628825045.3146.10499037245243838808@kernel.org> (raw)
In-Reply-To: <20261202084022.3716891-4-kyle.switch@motor-comm.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] The commit message of "net: dsa: motorcomm: use GENMASK_U32() for
mbus phy_mask" says "GENMASK_U32() also lets the compiler reject out-…
- [Low] yt921x_mbus_int_init() (drivers/net/dsa/motorcomm/mdio_bus.c)
leaks the mii_bus on the invalid-max_ports error path.
--
net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask
This commit changes how yt921x_mbus_int_init() builds the internal MDIO
bus phy_mask. It now uses GENMASK_U32() instead of a (u32) cast of
GENMASK() and drops the explicit cast. It is described as no functional
change.
> GENMASK_U32() also lets the compiler reject out-of-range masks at build
> time.
[Severity: Low]
Does this hold for the call site changed here? In yt921x_mbus_int_init()
the high bit is max_ports - 1, and max_ports is read at runtime:
max_ports = priv->series->max_ports;
GENMASK_U32() goes through GENMASK_TYPE(), whose input check is:
include/linux/bits.h:
#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h)))
const_true() is 0 for non-constant expressions. -Wshift-count-overflow
also only fires for constant shift counts. So no build-time check applies
here.
The only bound on the shift is the runtime check:
if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) {
This works today only because YT921X_PORT_NUM is 11. Nothing ties
ARRAY_SIZE(priv->ports) to BITS_PER_TYPE(u32). If ports[] ever grew past
32 entries, the shift inside GENMASK_TYPE() would get a negative count,
and the compiler would not warn.
The earlier commit "net: dsa: motorcomm: use max_ports in series for port
bounds checking" has a similar problem. It says it validates "the u32
width of phy_mask", but it only compares against ARRAY_SIZE(priv->ports).
Could this sentence be dropped? Alternatively, adding
BUILD_BUG_ON(ARRAY_SIZE(priv->ports) > BITS_PER_TYPE(u32)) would make the
claim true. The code change itself looks correct for max_ports in 1..11.
> diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c
> index a06e2cc94a3e2..94087c9962cca 100644
> --- a/drivers/net/dsa/motorcomm/mdio_bus.c
> +++ b/drivers/net/dsa/motorcomm/mdio_bus.c
> @@ -173,7 +173,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
> dev_err(dev, "Invalid max_ports: %u\n", max_ports);
> return -EINVAL;
> }
[Severity: Low]
Does this return leak the mii_bus? Earlier in yt921x_mbus_int_init() the
bus is allocated:
mbus = mdiobus_alloc();
if (!mbus)
return -ENOMEM;
The return -EINVAL above does not call mdiobus_free(mbus). mbus has not
been stored in priv->mbus_int yet, so yt921x_mbus_int_cleanup() cannot
free it either. The of_mdiobus_register() failure path just below does
call mdiobus_free().
The current yt92xx_series_table entries cannot reach this path, since
max_ports values of 11 and 9 both pass the check. The check came from the
earlier commit "net: dsa: motorcomm: use max_ports in series for port
bounds checking" in this series, and the leak is still there at the end
of the series.
Could the max_ports check move before mdiobus_alloc()? Calling
mdiobus_free(mbus) before returning -EINVAL would also work.
> - mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0);
> + mbus->phy_mask = ~GENMASK_U32(max_ports - 1, 0);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com
next prev parent reply other threads:[~2026-12-03 8:57 UTC|newest]
Thread overview: 17+ 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:40 ` sashiko-bot
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:40 ` sashiko-bot
2026-12-03 8:57 ` netdev-bot+sashiko
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 [this message]
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:40 ` sashiko-bot
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=179628825045.3146.10499037245243838808@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