From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>,
mfd@lists.linux.dev, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, lee@kernel.org
Subject: Re: [PATCH v3 4/4] mfd: an8855: Add support for Airoha AN8855 Switch
Date: Wed, 18 Nov 2026 16:42:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-221533@kernel.org> (raw)
In-Reply-To: <20261117164132.47167-5-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] mfd: an8855: missing reset-gpios handling in an8855_probe()
- [Medium] mfd: an8855: missing PHY_MAX_ADDR check in
an8855_phy_bus_register()
- [Medium] mfd: an8855: PHY registration before efuse MFD cell in
an8855_probe()
- [Low] mfd: an8855: cleanup helper and goto mixing in
an8855_mdio_register()
--
commit b4187acae4b9834706a08e5702a986758362581b
Author: Christian Marangi <ansuelsmth@gmail.com>
mfd: an8855: Add support for Airoha AN8855 Switch
This commit adds the core MFD driver for the Airoha AN8855 switch,
providing regmap access over MDIO, virtual MDIO buses for the internal
PHYs, and MFD cells for the efuse NVMEM provider and DSA switch.
> diff --git a/drivers/mfd/airoha-an8855.c b/drivers/mfd/airoha-an8855.c
> new file mode 100644
> index 0000000000000..908b2676e35a6
> --- /dev/null
> +++ b/drivers/mfd/airoha-an8855.c
[ ... ]
> +static int an8855_phy_bus_register(struct device *dev, struct an8855 *ddata,
> + struct fwnode_handle *phy_np,
> + struct an8855_phy_bus *phy_bus_info)
> +{
> + struct mdio_regmap_config mrc = { };
> + struct an8855_phy *phy_ddata;
> + struct regmap *regmap;
> + u32 addr, phy_offset;
> + struct mii_bus *bus;
> + int ret;
> +
> + ret = fwnode_property_read_u32(phy_np, "reg", &addr);
> + if (ret)
> + return ret;
> +
> + phy_offset = addr - ddata->switch_addr;
> + if (phy_offset >= AN8855_MAX_PHY_PORT)
> + return -EINVAL;
[Severity: Medium]
Can addr exceed PHY_MAX_ADDR - 1 here when ddata->switch_addr is 28..31?
If a child PHY node specifies reg >= 32 while addr - ddata->switch_addr is
still less than AN8855_MAX_PHY_PORT (5), an8855_probe() passes addr to
fwnode_mdiobus_register_phy() -> fwnode_mdiobus_phy_device_register() ->
phy_device_register() -> mdiobus_register_device(), which indexes
mdio->irq[addr] and mdiodev->bus->mdio_map[addr] (both sized PHY_MAX_ADDR =
32) out of bounds and shifts 1 << addr.
[ ... ]
> +static int an8855_mdio_register(struct device *dev, struct an8855 *ddata,
> + struct an8855_phy_bus *phy_bus_infos)
> +{
> + struct fwnode_handle *mdio_np __free(fwnode_handle) = NULL;
> + int phy = 0;
> + int ret = 0;
> +
> + mdio_np = fwnode_get_named_child_node(dev_fwnode(dev), "mdio");
> + if (!mdio_np)
> + return -ENODEV;
> +
> + fwnode_for_each_available_child_node_scoped(mdio_np, phy_np) {
> + if (phy >= AN8855_MAX_PHY_PORT) {
> + ret = -EINVAL;
> + goto exit;
> + }
> +
> + ret = an8855_phy_bus_register(dev, ddata, phy_np,
> + &phy_bus_infos[phy]);
> + if (ret)
> + goto exit;
> +
> + phy++;
> + }
> +
> +exit:
> + if (ret) {
> + while (phy--)
> + fwnode_handle_put(phy_bus_infos[phy].node);
> +
> + return ret;
> + }
> +
> + return phy;
> +}
[Severity: Low]
This isn't a bug, but an8855_mdio_register() mixes scope-based cleanup
helpers (__free(fwnode_handle) and
fwnode_for_each_available_child_node_scoped()) with goto error handling,
and declares mdio_np = NULL at the top of the function instead of defining
and initializing it in one statement.
> +
> +static int an8855_probe(struct mdio_device *mdiodev)
> +{
[ ... ]
> + /* Reset PHY page for switch address */
> + mutex_lock_nested(&ddata->bus->mdio_lock, MDIO_MUTEX_NESTED);
> + ret = an8855_mii_set_page(ddata, ddata->switch_addr,
> + AN8855_PHY_PAGE_STANDARD);
> + mutex_unlock(&ddata->bus->mdio_lock);
> + if (ret)
> + goto err_put_fwnodes;
> +
> + ret = an8855_read_switch_id(dev, regmap);
> + if (ret)
> + goto err_put_fwnodes;
> +
> + /* Release global PHY power down */
> + ret = regmap_write(regmap, AN8855_RG_GPHY_AFE_PWD, 0x0);
> + if (ret)
> + goto err_put_fwnodes;
[Severity: High]
Should an8855_probe() acquire and deassert reset-gpios before accessing the
switch over MDIO?
The airoha,an8855 binding places reset-gpios on this MFD node, and the MDIO
core only handles reset-gpios for PHY devices:
drivers/net/phy/mdio_device.c:mdiobus_register_device() {
...
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
err = mdio_device_register_reset(mdiodev);
if (err)
return err;
/* Assert the reset signal */
mdio_device_reset(mdiodev, 1);
}
...
}
On boards where reset-gpios is asserted at boot, an8855_mii_set_page() or
an8855_read_switch_id() will read 0xffff while the SoC is held in reset and
fail probe with -ENODEV. Conversely, if a child driver resets the chip
later during devm_mfd_add_devices(), it will wipe out the
AN8855_RG_GPHY_AFE_PWD write and internal PHY state configured here.
Also, <linux/gpio/consumer.h> and AN8855_HWTRAP at the top of the file are
currently unused.
> +
> + /* Register PHYs */
> + for (phy = 0; phy < num_phys; phy++) {
> + ret = fwnode_mdiobus_register_phy(phy_bus_infos[phy].bus,
> + phy_bus_infos[phy].node,
> + phy_bus_infos[phy].addr);
> + fwnode_handle_put(phy_bus_infos[phy].node);
> + phy_bus_infos[phy].node = NULL;
> +
> + if (ret)
> + goto err_put_fwnodes;
> + }
> +
> + return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, an8855_cells,
> + ARRAY_SIZE(an8855_cells), NULL, 0,
> + NULL);
[Severity: Medium]
Does registering the internal PHYs before an8855-efuse cause them to defer
probe and risk binding to genphy_driver?
The internal ethernet-phy nodes consume nvmem-cells from an8855-efuse, so
fw_devlink defers each PHY probe during fwnode_mdiobus_register_phy()
because an8855-efuse has not been registered yet. When
devm_mfd_add_devices() then registers an8855-efuse and immediately probes
an8855-switch in the same loop, an8855-switch can call phy_attach_direct()
before deferred_probe_work runs on the workqueue; phy_attach_direct() sees
!d->driver on the deferred PHY and binds genphy_driver instead of the
AN8855 PHY driver.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117164132.47167-1-ansuelsmth@gmail.com?part=4
prev parent reply other threads:[~2026-11-18 16:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:41 [PATCH v3 0/4] an8855: add MFD driver Christian Marangi
2026-11-17 16:41 ` [PATCH v3 1/4] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch Christian Marangi
2026-11-17 16:41 ` [PATCH v3 2/4] dt-bindings: net: Document support for AN8855 Switch Internal PHY Christian Marangi
2026-11-17 16:41 ` [PATCH v3 3/4] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC Christian Marangi
2026-11-17 16:41 ` [PATCH v3 4/4] mfd: an8855: Add support for Airoha AN8855 Switch Christian Marangi
2026-11-18 16:42 ` sashiko-bot [this message]
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=sashiko-outbox-221533@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=lee@kernel.org \
--cc=mfd@lists.linux.dev \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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