Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Yang" <mmyangfl@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v4 5/5] net: hix5hd2_gmac: Support fixed-link
Date: Fri, 27 Nov 2026 00:56:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-236380@kernel.org> (raw)
In-Reply-To: <20261126005524.4156940-6-mmyangfl@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] net: hix5hd2_gmac: NULL dereference in hix5hd2_dev_remove() on
  fixed-link
- [Medium] net: hix5hd2_gmac: broken phy-handle precedence in
  hix5hd2_dev_probe()
--

commit 557f552e688f91f0f04fafd2daf29129d331e0f6
Author: David Yang <mmyangfl@gmail.com>

net: hix5hd2_gmac: Support fixed-link

This commit adds fixed-link support to hix5hd2_gmac by registering a fixed
PHY when no phy-handle is present and skipping MDIO bus registration unless
an mdio child node is defined.

> diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
> index b3b2aa1b76988..eeb7221c0cde8 100644
> --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
> +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c
> @@ -1176,37 +1176,55 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
>  		hix5hd2_phy_reset(priv);
>  	}
>  
> -	bus = devm_mdiobus_alloc(dev);
> -	if (bus == NULL) {
> -		ret = -ENOMEM;
> +	priv->phy_node = of_parse_phandle(node, "phy-handle", 0);
> +
> +	/* In the case of a fixed PHY, the DT node associated
> +	 * to the PHY is the Ethernet MAC DT node.
> +	 */
> +	if (!priv->phy_node && of_phy_is_fixed_link(node)) {
> +		ret = of_phy_register_fixed_link(node);
> +		if (ret < 0)
> +			goto out_disable_clk;
> +		priv->phy_node = of_node_get(node);
> +	} else if (!priv->phy_node) {
> +		netdev_err(ndev, "not find phy-handle\n");
> +		ret = -EINVAL;
>  		goto out_disable_clk;
>  	}
>  
> -	bus->priv = priv;
> -	bus->name = "hix5hd2_mii_bus";
> -	bus->read = hix5hd2_mdio_read;
> -	bus->write = hix5hd2_mdio_write;
> -	bus->parent = &pdev->dev;
> -	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
> -	priv->bus = bus;
> -
> +	bus = NULL;
>  	mdio_np = of_get_available_child_by_name(node, "mdio");
> -	ret = of_mdiobus_register(bus, mdio_np ?: node);
> +	if (mdio_np || (priv->phy_node != node &&
> +			!of_phy_is_fixed_link(node))) {

[Severity: Medium]
Does checking !of_phy_is_fixed_link(node) here break phy-handle precedence
when the MAC node has both phy-handle and managed = "in-band-status"
without an mdio child node?

In that configuration of_phy_is_fixed_link(node) is true even though
priv->phy_node != node, so hix5hd2_dev_probe() skips registering the MDIO
bus and of_phy_connect() in hix5hd2_net_open() fails to find the PHY.
Since priv->phy_node == node already tracks whether a fixed link was
registered, checking if (mdio_np || priv->phy_node != node) would avoid
this.

[ ... ]

> @@ -1271,9 +1289,11 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
>  	netif_napi_del(&priv->napi);
>  	hix5hd2_destroy_hw_desc_queue(priv);
>  out_phy_node:
> +	if (priv->phy_node == node)
> +		of_phy_deregister_fixed_link(node);
>  	of_node_put(priv->phy_node);
> -err_mdiobus:
> -	mdiobus_unregister(bus);
> +	if (bus)
> +		mdiobus_unregister(bus);
>  out_disable_clk:
>  	clk_disable_unprepare(priv->mac_ifc_clk);
>  out_disable_mac_core_clk:
> @@ -1294,6 +1314,8 @@ static void hix5hd2_dev_remove(struct platform_device *pdev)
>  	if (HAS_CAP_TSO(priv->hw_cap))
>  		hix5hd2_destroy_sg_desc_queue(priv);
>  	hix5hd2_destroy_hw_desc_queue(priv);
> +	if (priv->phy_node == pdev->dev.of_node)
> +		of_phy_deregister_fixed_link(pdev->dev.of_node);
>  	of_node_put(priv->phy_node);
>  }

[Severity: High]
Does hix5hd2_dev_remove() trigger a NULL pointer dereference in
mdiobus_unregister(priv->bus) when a fixed-link device has no mdio child
node?

When MDIO bus registration is skipped in hix5hd2_dev_probe(), priv->bus
remains NULL.  The probe error path guards mdiobus_unregister() with
if (bus), but hix5hd2_dev_remove() still calls
mdiobus_unregister(priv->bus) unconditionally, and mdiobus_unregister()
immediately dereferences bus->state.

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

      reply	other threads:[~2026-11-27  0:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  0:55 [PATCH net-next v4 0/5] net: hix5hd2_gmac: Support fixed-link David Yang
2026-11-26  0:55 ` [PATCH net-next v4 1/5] net: hix5hd2_gmac: Use devm_ managed netdev and MDIO bus David Yang
2026-11-26  0:55 ` [PATCH net-next v4 2/5] dt-bindings: net: hisilicon,hisi-gmac-v1: Add mdio bus child node David Yang
2026-11-26  0:55 ` [PATCH net-next v4 3/5] net: hix5hd2_gmac: Use mdio child node for MDIO bus if it exists David Yang
2026-11-26  0:55 ` [PATCH net-next v4 4/5] dt-bindings: net: hisilicon,hisi-gmac-v1: Allow fixed-link David Yang
2026-11-26  0:55 ` [PATCH net-next v4 5/5] net: hix5hd2_gmac: Support fixed-link David Yang
2026-11-27  0:56   ` 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-236380@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=mmyangfl@gmail.com \
    --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