All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Coia Prant" <coiaprant@gmail.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH net-next v11 5/6] net: stmmac: dwmac-rk: add SGMII support for RK3568
Date: Fri, 09 Oct 2026 17:53:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-165904@kernel.org> (raw)
In-Reply-To: <20261008175225.3375274-6-coiaprant@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: stmmac: dw_xpcs memory leak and overwrite in stmmac_pcs_setup
--

commit de93d801ba1c997500b23cca54a77392e6107f28
Author: Coia Prant <coiaprant@gmail.com>

net: stmmac: dwmac-rk: add SGMII support for RK3568

The RK3568 SoC integrates a Synopsys DesignWare XPCS that can be connected
to GMAC0 or GMAC1 in SGMII mode. This commit adds the necessary glue logic
to support this configuration in the dwmac-rk driver.

Link: https://dl.radxa.com/rock3/docs/hw/datasheet/Rockchip%20RK3568%20TRM%20Part1%20V1.1-20210301.pdf (Page 386)

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
[ ... ]
> @@ -1211,6 +1239,44 @@ static void rk_phy_powerdown(struct rk_priv_data *bsp_priv)
[ ... ]
> +static int rk_pcs_init(struct stmmac_priv *priv)
> +{
> +	struct rk_priv_data *bsp_priv = priv->plat->bsp_priv;
> +	struct device_node *node = priv->device->of_node;
> +	struct device_node *pcs_node;
> +	struct dw_xpcs *xpcs;
> +
> +	pcs_node = of_parse_phandle(node, "pcs-handle", 0);
> +	if (!pcs_node)
> +		return -ENODEV;
> +
> +	xpcs = xpcs_rk_create(priv->device, pcs_node, bsp_priv->id);
> +	of_node_put(pcs_node);
> +	if (IS_ERR(xpcs))
> +		return PTR_ERR(xpcs);
> +
> +	priv->hw->xpcs = xpcs;
> +	return 0;
> +}

[Severity: High]
Does this code leak the newly allocated XPCS instance when interacting with
stmmac_pcs_setup() in the core driver?

Looking at stmmac_pcs_setup() in drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c,
it declares a local xpcs variable initialized to NULL:

int stmmac_pcs_setup(struct net_device *ndev)
{
	struct dw_xpcs *xpcs = NULL;
	...
	if (priv->plat->pcs_init) {
		ret = priv->plat->pcs_init(priv);
	...
	priv->hw->xpcs = xpcs;

	return 0;
}

Because rk_pcs_init() successfully allocates the XPCS and assigns it directly
to priv->hw->xpcs, it returns 0.

The local variable xpcs in stmmac_pcs_setup() remains NULL. At the end of
stmmac_pcs_setup(), it unconditionally overwrites the newly allocated pointer
in priv->hw->xpcs with NULL.

Will this cause the MAC to lose its PCS reference and break SGMII link
negotiation?

Additionally, does this leak the dw_xpcs object memory, since teardown
functions like rk_pcs_exit() will see a NULL pointer and exit early?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261008175225.3375274-1-coiaprant@gmail.com?part=5

  reply	other threads:[~2026-10-09 17:53 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 17:51 [PATCH net-next v11 0/6] net: pcs: add basic support for RK3568 XPCS Coia Prant
2026-10-08 17:51 ` Coia Prant
2026-10-08 17:51 ` [PATCH net-next v11 1/6] net: pcs: xpcs: add ANRESTART support for SGMII link recovery Coia Prant
2026-10-08 17:51   ` Coia Prant
2026-10-12 19:01   ` netdev-bot+sashiko
2026-10-12 19:01     ` netdev-bot+sashiko
2026-10-12 19:24     ` Coia Prant
2026-10-12 19:24       ` Coia Prant
2026-10-08 17:51 ` [PATCH net-next v11 2/6] dt-bindings: net: pcs: add rockchip,rk3568-xpcs support Coia Prant
2026-10-08 17:51   ` Coia Prant
2026-10-09 16:49   ` Rob Herring (Arm)
2026-10-09 16:49     ` Rob Herring (Arm)
2026-10-09 17:53   ` sashiko-bot
2026-10-12 19:01   ` netdev-bot+sashiko
2026-10-12 19:01     ` netdev-bot+sashiko
2026-10-08 17:51 ` [PATCH net-next v11 3/6] net: pcs: xpcs: add Rockchip RK3568 platform glue driver Coia Prant
2026-10-08 17:51   ` Coia Prant
2026-10-09 17:53   ` sashiko-bot
2026-10-12 19:01   ` netdev-bot+sashiko
2026-10-12 19:01     ` netdev-bot+sashiko
2026-10-08 17:51 ` [PATCH net-next v11 4/6] dt-bindings: net: rockchip-dwmac: document pcs-handle Coia Prant
2026-10-08 17:51   ` Coia Prant
2026-10-09 16:50   ` Rob Herring (Arm)
2026-10-09 16:50     ` Rob Herring (Arm)
2026-10-12 19:01   ` netdev-bot+sashiko
2026-10-12 19:01     ` netdev-bot+sashiko
2026-10-08 17:51 ` [PATCH net-next v11 5/6] net: stmmac: dwmac-rk: add SGMII support for RK3568 Coia Prant
2026-10-08 17:51   ` Coia Prant
2026-10-09 17:53   ` sashiko-bot [this message]
2026-10-12 19:01   ` netdev-bot+sashiko
2026-10-12 19:01     ` netdev-bot+sashiko
2026-10-08 17:52 ` [PATCH net-next v11 6/6] MAINTAINERS: add entry for Rockchip XPCS driver Coia Prant
2026-10-08 17:52   ` Coia Prant

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-165904@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=coiaprant@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --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 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.