All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vasilij Strassheim" <v.strassheim@linutronix.de>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH 4/4] net: dsa: soce: Add initial driver support for MRS switches
Date: Thu, 30 Jul 2026 16:37:58 +0000	[thread overview]
Message-ID: <20260730163758.659C91F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260729-devel-vstrassheim-soce-dsa-ml-v1-4-be569dae1b20@linutronix.de>

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Incorrect error check for `devm_of_iomap()` leads to potential NULL pointer dereference on mapping failure.
- [High] The `ds->phys_mii_mask` is never initialized, causing the driver's custom MDIO bus to silently ignore all PHY reads and writes.
- [High] Concurrent MDIO accesses via `slave_mii_bus` and `user_mii_bus` race on shared hardware registers, causing state corruption.
- [Medium] Missing bitmasks on input parameters in MDIO hardware register construction allows out-of-bounds values to corrupt adjacent register fields.
- [Medium] The driver unconditionally issues a flush command to the hardware FDB controller even if the previous command is still being processed.
- [Medium] Asynchronous, switch-wide FDB flush is performed instead of a synchronous, per-port flush.
--

--- Patch [4]: [PATCH 4/4] net: dsa: soce: Add initial driver support for MRS switches ---
commit 4ad10a20f72f216349a16415f424608c5d3e5c86
Author: Vasilij Strassheim <v.strassheim@linutronix.de>

net: dsa: soce: Add initial driver support for MRS switches

This commit adds initial support for SoC-e switches based on FPGA IP cores.
It provides MDIO access helpers for supported IP register layouts and common
STP/FDB handling.

> diff --git a/drivers/net/dsa/soce/soce_common.c b/drivers/net/dsa/soce/soce_common.c
> index 0000000000000..f7f345a690e46
> --- /dev/null
> +++ b/drivers/net/dsa/soce/soce_common.c

[ ... ]

> +static void soce_fast_age(struct dsa_switch *ds, int port,
> +			  const struct soce_layout *layout)
> +{
> +	struct soce_priv *priv = ds->priv;
> +	struct soce_dsa_local *local;
> +	void __iomem *p_mes_ctrl;
> +	u32 val;
> +
> +	local = &priv->local;
> +	if (!layout || !local->base_addr)
> +		return;
> +
> +	p_mes_ctrl = local->base_addr + layout->fdb_ctrl;
> +	if (readl_poll_timeout(p_mes_ctrl, val,
> +			       !(val & SOCE_FDB_CLEAR_UNDER_PROCESS),
> +			       SOCE_FAST_AGE_POLL_US, SOCE_FAST_AGE_TIMEOUT_US))
> +		dev_warn(ds->dev, "SoC-e fast_age timeout on port %d\n", port);
> +
> +	writel(SOCE_FDB_CLEAR_FLUSH_MSTID, p_mes_ctrl);

[Severity: Medium]
Does this code continue to issue the flush command even if the hardware is
still processing the previous one? If readl_poll_timeout() fails, it prints
a warning but unconditionally executes the writel() below it.

[Severity: Medium]
Will this flush the entire MSTID globally rather than just the specified port?
The command ignores the port argument. Additionally, it appears to return
immediately without waiting for the clear operation to complete.

> +}

[ ... ]

> diff --git a/drivers/net/dsa/soce/soce_dsa_core.c b/drivers/net/dsa/soce/soce_dsa_core.c
> index 0000000000000..b88d00c56d718
> --- /dev/null
> +++ b/drivers/net/dsa/soce/soce_dsa_core.c

[ ... ]

> +static int soce_phy_read(struct dsa_switch *ds, int port, int regnum)
> +{
> +	struct soce_priv *priv = ds->priv;
> +	struct soce_dsa_local *local;
> +
> +	local = &priv->local;
> +	if (!local->mdio_ops || !local->mdio_ops->phy_read)
> +		return 0xffff;
> +
> +	return local->mdio_ops->phy_read(ds, port, regnum);
> +}

[Severity: High]
Can concurrent MDIO accesses race on the shared hardware registers here?
The DSA core implicitly registers the slave_mii_bus, and the driver explicitly
registers a user_mii_bus. Both buses have their own independent mdio_lock
mutex, but they share the same underlying MMIO routines.

[ ... ]

> +static int soce_sw_probe(struct mdio_device *mdiodev)
> +{
[ ... ]
> +	local->base_addr = devm_of_iomap(dev, switch_node, 0, NULL);
> +	if (IS_ERR(local->base_addr)) {
> +		dev_err(dev, "failed to map switch register space for %pOF\n",
> +			switch_node);
> +		of_node_put(switch_node);
> +		return PTR_ERR(local->base_addr);
> +	}

[Severity: High]
Does devm_of_iomap() return NULL on failure rather than an error pointer?
Checking IS_ERR() here will evaluate to false if it returns NULL, leading to a
potential NULL pointer dereference later when accessing the MMIO base.

[ ... ]

> diff --git a/drivers/net/dsa/soce/soce_mdio.c b/drivers/net/dsa/soce/soce_mdio.c
> index 0000000000000..241fc373de8b8
> --- /dev/null
> +++ b/drivers/net/dsa/soce/soce_mdio.c

[ ... ]

> +static int soce_user_phy_read(struct mii_bus *bus, int addr, int reg)
> +{
> +	struct dsa_switch *ds = bus->priv;
> +
> +	if (ds->phys_mii_mask & BIT(addr))
> +		return ds->ops->phy_read(ds, addr, reg);
> +
> +	return 0xffff;
> +}

[Severity: High]
Is ds->phys_mii_mask ever initialized? It appears to default to 0 when
allocated in soce_sw_probe(). If it is always 0, this check will fail and
all user PHY reads will silently return 0xffff.

[ ... ]

> +int soce_user_mii_bus_register(struct dsa_switch *ds)
> +{
[ ... ]
> +	ds->user_mii_bus->parent = ds->dev;
> +	ds->user_mii_bus->phy_mask = ~ds->phys_mii_mask;

[Severity: High]
Since ds->phys_mii_mask defaults to 0, will setting phy_mask to the inverted
value instruct the MDIO core to ignore all PHYs and prevent probing entirely?

[ ... ]

> +int soce_mdio_20_03_write(struct dsa_switch *ds, int portnumber, int regnum,
> +			  u16 val)
> +{
[ ... ]
> +	/* Then write control */
> +	regvalue = (mdio->phy_addr << SOCE_MDIO_20_03_CTRL_PHY_ADDR_SHIFT) |
> +		   (regnum << SOCE_MDIO_20_03_CTRL_REG_ADDR_SHIFT) |
> +		   SOCE_MDIO_20_03_CTRL_OP_WRITE |
> +		   SOCE_MDIO_20_03_CTRL_START |
> +		   mdio->mdio_output;
> +	writel(regvalue, ctrl);

[Severity: Medium]
Should the phy_addr and regnum inputs be bounded or masked before shifting?
If an oversized regnum is passed in via userspace ioctls, or a malformed DT
provides a large soce,phy-addr, the shifted bits could overflow into adjacent
control register fields.

[ ... ]

> +static int soce_mdio_23_02_read_c22(struct dsa_switch *ds, int portnumber,
> +				    int regnum)
> +{
[ ... ]
> +	regvalue = (regnum << SOCE_MDIO_23_02_CTRL_REGADDRDEVTYPE_OFFSET) +
> +		   (mdio->phy_addr << SOCE_MDIO_23_02_CTRL_PHYADDR_OFFSET);
> +	writel(regvalue, params);

[Severity: Medium]
Similarly here, can the addition of unmasked values risk arithmetic overflow
into adjacent bit ranges if the inputs are out-of-bounds?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260729-devel-vstrassheim-soce-dsa-ml-v1-0-be569dae1b20@linutronix.de?part=4

  parent reply	other threads:[~2026-07-30 16:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 16:36 [PATCH 0/4] net: dsa: Add SoC-e DSA driver Vasilij Strassheim
2026-07-29 16:36 ` [PATCH 1/4] dt-bindings: vendor-prefixes: Add soce Vasilij Strassheim
2026-07-30  8:50   ` Krzysztof Kozlowski
2026-07-29 16:36 ` [PATCH 2/4] dt-bindings: net: dsa: Add SoC-e switch IP and DSA bindings Vasilij Strassheim
2026-07-29 17:11   ` Andrew Lunn
2026-07-29 18:07   ` Rob Herring (Arm)
2026-07-30  8:56   ` Krzysztof Kozlowski
2026-07-30  8:56   ` Krzysztof Kozlowski
2026-07-30 16:37   ` sashiko-bot
2026-07-29 16:36 ` [PATCH 3/4] net: dsa: Add support for SoC-e SDSA tags Vasilij Strassheim
2026-07-29 17:22   ` Andrew Lunn
2026-07-30 16:37   ` sashiko-bot
2026-07-29 16:36 ` [PATCH 4/4] net: dsa: soce: Add initial driver support for MRS switches Vasilij Strassheim
2026-07-29 17:31   ` Andrew Lunn
2026-07-29 20:05   ` Andrew Lunn
2026-07-30  9:01   ` Krzysztof Kozlowski
2026-07-30 16:37   ` sashiko-bot [this message]
2026-07-29 16:56 ` [PATCH 0/4] net: dsa: Add SoC-e DSA driver Andrew Lunn

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=20260730163758.659C91F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=v.strassheim@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.