All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: conor+dt@kernel.org, neil.armstrong@linaro.org, robh@kernel.org,
	linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
	vkoul@kernel.org, olteanv@gmail.com
Subject: Re: [PATCH v7 4/6] clk: en7523: Add support for selecting the Serdes port in SCU
Date: Tue, 19 May 2026 22:40:08 +0000	[thread overview]
Message-ID: <20260519224008.A9DF61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260519220813.28468-5-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] The `reg` and `mask` variables are left uninitialized when processing the `AIROHA_SCU_SERDES_PCIE2` case, leading to arbitrary memory/hardware corruption.
- [High] Concurrent read-modify-write operations on shared hardware registers lack spinlock protection, leading to race conditions and potential lost updates.
- [High] USB PHY instances unconditionally reject `PHY_MODE_USB_HOST` and `PHY_MODE_USB_OTG`, breaking USB host functionality.
--

commit 714fd2f968cbdacf2f17f7ead8459ffad971d307
Author: Christian Marangi <ansuelsmth@gmail.com>
Subject: clk: en7523: Add support for selecting the Serdes port in SCU

This commit adds support for selecting the Serdes port in the SCU register 
for clock and reset. It implements a simple PHY provider with a set_mode 
operation to toggle the requested mode (PCIe, USB, or Ethernet) for the 
Airoha AN7581 SoC Serdes ports.

> diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> index 1ab0e2eca5d32..58ec071388a4d 100644
> --- a/drivers/clk/clk-en7523.c
> +++ b/drivers/clk/clk-en7523.c
[ ... ]
> @@ -830,12 +858,173 @@ static int en7581_reset_register(struct device *dev, void __iomem *base,
> +static int en7581_serdes_phy_set_mode(struct phy *phy, enum phy_mode mode,
> +				      int submode)
> +{
> +	struct en_serdes_phy_instance *instance = phy_get_drvdata(phy);
> +	struct en_clk_priv *priv = dev_get_drvdata(phy->dev.parent);
> +	u32 reg, mask, sel, val;
> +
> +	switch (instance->serdes_port) {
> +	case AIROHA_SCU_SERDES_PCIE1:
> +		reg = REG_NP_SCU_SSTR;
> +		mask = REG_PCIE_XSI0_SEL_MASK;
[ ... ]
> +		} else {
> +			sel = REG_PCIE_XSI0_SEL_PCIE;
> +		}
> +
> +		break;
> +	case AIROHA_SCU_SERDES_PCIE2:

[Severity: Critical]
Could this cause random memory or hardware corruption?

It looks like reg and mask are not initialized for AIROHA_SCU_SERDES_PCIE2
here. When the switch statement finishes, the function uses these
uninitialized stack variables for the readl and writel operations.

> +		if (mode != PHY_MODE_ETHERNET && mode != PHY_MODE_PCIE)
> +			return -EINVAL;
[ ... ]
> +		} else {
> +			sel = REG_PCIE_XSI1_SEL_PCIE;
> +		}
> +
> +		break;
> +	case AIROHA_SCU_SERDES_USB1:
> +		reg = REG_NP_SCU_SSR3;
> +		mask = REG_SSUSB_HSGMII_SEL_MASK;
> +
> +		if (mode != PHY_MODE_ETHERNET && mode != PHY_MODE_USB_DEVICE &&
> +		    mode != PHY_MODE_USB_DEVICE_SS)
> +			return -EINVAL;

[Severity: High]
Will this break USB host or dual-role functionality?

USB controllers operating in host or OTG modes often request
PHY_MODE_USB_HOST or PHY_MODE_USB_OTG. Since this PHY only acts as a
multiplexer, should it accept all valid USB modes when routing lines to the
USB controller?

> +
> +		if (mode == PHY_MODE_ETHERNET)
> +			sel = REG_SSUSB_HSGMII_SEL_HSGMII;
> +		else
> +			sel = REG_SSUSB_HSGMII_SEL_USB;
> +
> +		break;
> +	case AIROHA_SCU_SERDES_USB2:
> +		reg = REG_NP_SCU_SSTR;
> +		mask = REG_USB_PCIE_SEL_MASK;
[ ... ]
> +		if (mode == PHY_MODE_PCIE)
> +			sel = REG_USB_PCIE_SEL_PCIE;
> +		else
> +			sel = REG_USB_PCIE_SEL_USB;
> +
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	val = readl(priv->base + reg);
> +	val &= ~mask;
> +	val |= sel;
> +	writel(val, priv->base + reg);

[Severity: High]
Can this read-modify-write sequence race if multiple Serdes ports are
configured concurrently?

The PHY subsystem uses a per-PHY instance mutex, so the set_mode callbacks
for different Serdes ports could execute in parallel (for example, during
asynchronous probing). Because they share hardware registers like
REG_NP_SCU_SSTR, concurrent operations could lead to lost updates and route
the Serdes to the wrong subsystem.

Would it be safer to protect these accesses with a spinlock added to struct
en_clk_priv?

> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260519220813.28468-1-ansuelsmth@gmail.com?part=4

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: conor+dt@kernel.org, neil.armstrong@linaro.org, robh@kernel.org,
	linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
	vkoul@kernel.org, olteanv@gmail.com
Subject: Re: [PATCH v7 4/6] clk: en7523: Add support for selecting the Serdes port in SCU
Date: Tue, 19 May 2026 22:40:08 +0000	[thread overview]
Message-ID: <20260519224008.A9DF61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260519220813.28468-5-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] The `reg` and `mask` variables are left uninitialized when processing the `AIROHA_SCU_SERDES_PCIE2` case, leading to arbitrary memory/hardware corruption.
- [High] Concurrent read-modify-write operations on shared hardware registers lack spinlock protection, leading to race conditions and potential lost updates.
- [High] USB PHY instances unconditionally reject `PHY_MODE_USB_HOST` and `PHY_MODE_USB_OTG`, breaking USB host functionality.
--

commit 714fd2f968cbdacf2f17f7ead8459ffad971d307
Author: Christian Marangi <ansuelsmth@gmail.com>
Subject: clk: en7523: Add support for selecting the Serdes port in SCU

This commit adds support for selecting the Serdes port in the SCU register 
for clock and reset. It implements a simple PHY provider with a set_mode 
operation to toggle the requested mode (PCIe, USB, or Ethernet) for the 
Airoha AN7581 SoC Serdes ports.

> diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> index 1ab0e2eca5d32..58ec071388a4d 100644
> --- a/drivers/clk/clk-en7523.c
> +++ b/drivers/clk/clk-en7523.c
[ ... ]
> @@ -830,12 +858,173 @@ static int en7581_reset_register(struct device *dev, void __iomem *base,
> +static int en7581_serdes_phy_set_mode(struct phy *phy, enum phy_mode mode,
> +				      int submode)
> +{
> +	struct en_serdes_phy_instance *instance = phy_get_drvdata(phy);
> +	struct en_clk_priv *priv = dev_get_drvdata(phy->dev.parent);
> +	u32 reg, mask, sel, val;
> +
> +	switch (instance->serdes_port) {
> +	case AIROHA_SCU_SERDES_PCIE1:
> +		reg = REG_NP_SCU_SSTR;
> +		mask = REG_PCIE_XSI0_SEL_MASK;
[ ... ]
> +		} else {
> +			sel = REG_PCIE_XSI0_SEL_PCIE;
> +		}
> +
> +		break;
> +	case AIROHA_SCU_SERDES_PCIE2:

[Severity: Critical]
Could this cause random memory or hardware corruption?

It looks like reg and mask are not initialized for AIROHA_SCU_SERDES_PCIE2
here. When the switch statement finishes, the function uses these
uninitialized stack variables for the readl and writel operations.

> +		if (mode != PHY_MODE_ETHERNET && mode != PHY_MODE_PCIE)
> +			return -EINVAL;
[ ... ]
> +		} else {
> +			sel = REG_PCIE_XSI1_SEL_PCIE;
> +		}
> +
> +		break;
> +	case AIROHA_SCU_SERDES_USB1:
> +		reg = REG_NP_SCU_SSR3;
> +		mask = REG_SSUSB_HSGMII_SEL_MASK;
> +
> +		if (mode != PHY_MODE_ETHERNET && mode != PHY_MODE_USB_DEVICE &&
> +		    mode != PHY_MODE_USB_DEVICE_SS)
> +			return -EINVAL;

[Severity: High]
Will this break USB host or dual-role functionality?

USB controllers operating in host or OTG modes often request
PHY_MODE_USB_HOST or PHY_MODE_USB_OTG. Since this PHY only acts as a
multiplexer, should it accept all valid USB modes when routing lines to the
USB controller?

> +
> +		if (mode == PHY_MODE_ETHERNET)
> +			sel = REG_SSUSB_HSGMII_SEL_HSGMII;
> +		else
> +			sel = REG_SSUSB_HSGMII_SEL_USB;
> +
> +		break;
> +	case AIROHA_SCU_SERDES_USB2:
> +		reg = REG_NP_SCU_SSTR;
> +		mask = REG_USB_PCIE_SEL_MASK;
[ ... ]
> +		if (mode == PHY_MODE_PCIE)
> +			sel = REG_USB_PCIE_SEL_PCIE;
> +		else
> +			sel = REG_USB_PCIE_SEL_USB;
> +
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	val = readl(priv->base + reg);
> +	val &= ~mask;
> +	val |= sel;
> +	writel(val, priv->base + reg);

[Severity: High]
Can this read-modify-write sequence race if multiple Serdes ports are
configured concurrently?

The PHY subsystem uses a per-PHY instance mutex, so the set_mode callbacks
for different Serdes ports could execute in parallel (for example, during
asynchronous probing). Because they share hardware registers like
REG_NP_SCU_SSTR, concurrent operations could lead to lost updates and route
the Serdes to the wrong subsystem.

Would it be safer to protect these accesses with a spinlock added to struct
en_clk_priv?

> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260519220813.28468-1-ansuelsmth@gmail.com?part=4

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2026-05-19 22:40 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 22:08 [PATCH v7 0/6] airoha: an7581: USB support Christian Marangi
2026-05-19 22:08 ` Christian Marangi
2026-05-19 22:08 ` [PATCH v7 1/6] dt-bindings: soc: Add bindings for Airoha SCU Serdes lines Christian Marangi
2026-05-19 22:08   ` Christian Marangi
2026-05-19 22:08 ` [PATCH v7 2/6] dt-bindings: clock: airoha: Add PHY binding for Serdes port Christian Marangi
2026-05-19 22:08   ` Christian Marangi
2026-05-19 22:18   ` sashiko-bot
2026-05-19 22:18     ` sashiko-bot
2026-05-20  6:53   ` Krzysztof Kozlowski
2026-05-20  6:53     ` Krzysztof Kozlowski
2026-05-19 22:08 ` [PATCH v7 3/6] dt-bindings: phy: Add documentation for Airoha AN7581 USB PHY Christian Marangi
2026-05-19 22:08   ` Christian Marangi
2026-05-19 22:08 ` [PATCH v7 4/6] clk: en7523: Add support for selecting the Serdes port in SCU Christian Marangi
2026-05-19 22:08   ` Christian Marangi
2026-05-19 22:40   ` sashiko-bot [this message]
2026-05-19 22:40     ` sashiko-bot
2026-05-19 22:08 ` [PATCH v7 5/6] phy: move and rename Airoha PCIe PHY driver to dedicated directory Christian Marangi
2026-05-19 22:08   ` Christian Marangi
2026-05-19 22:58   ` sashiko-bot
2026-05-19 22:58     ` sashiko-bot
2026-05-20  3:57   ` Baruch Siach
2026-05-20  3:57     ` Baruch Siach
2026-05-19 22:08 ` [PATCH v7 6/6] phy: airoha: Add support for Airoha AN7581 USB PHY Christian Marangi
2026-05-19 22:08   ` Christian Marangi
2026-05-19 23:23   ` sashiko-bot
2026-05-19 23:23     ` sashiko-bot

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=20260519224008.A9DF61F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ansuelsmth@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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.