From: sashiko-bot@kernel.org
To: "Marek Vasut" <marek.vasut+renesas@mailbox.org>,
linux-phy@lists.infradead.org
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
vkoul@kernel.org, neil.armstrong@linaro.org, olteanv@gmail.com,
wsa+renesas@sang-engineering.com
Subject: Re: [PATCH v3 2/3] phy: renesas: Add Renesas Multi-Protocol PHY driver for R-Car X5H
Date: Tue, 01 Dec 2026 00:34:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-242269@kernel.org> (raw)
In-Reply-To: <20261201002008.413380-2-marek.vasut+renesas@mailbox.org>
Thank you for your contribution! Sashiko AI review found 10 potential
issues to consider:
- [High] phy: renesas: out-of-bounds access using global phy->id as
channel index
- [High] phy: renesas: broken PCIe 1 channel mapping and multi-lane
power domains
- [High] phy: renesas: broken runtime PM and clock/reset cleanup in
probe and remove
- [High] phy: renesas: misuse of regmap_set_bits() on W1C and multi-bit
fields
- [High] phy: renesas: broken system sleep ordering and state loss on
resume
- [Medium] phy: renesas: runtime PM usage count leak on error in
mp_phy_init()
- [Medium] phy: renesas: broken runtime PM init in mp_phy_probe()
- [Medium] phy: renesas: NULL priv->pd_list dereference after
mp_phy_probe()
- [Medium] phy: renesas: missing runtime PM rollback in
mp_phy_suspend_late()
- [Medium] phy: renesas: busy-spin polling in mp_phy_reg_wait() and
duplicate SRAM wait
--
commit ad97b96dbe810225e507504cb6c802f2c347b4c9
Author: Thanh Quan <thanh.quan.xn@renesas.com>
phy: renesas: Add Renesas Multi-Protocol PHY driver for R-Car X5H
This commit adds a driver for the Renesas Multi-Protocol PHY on the R-Car
X5H (R8A78000) SoC, multiplexing PCIe4, USB 3.2, and Ethernet PCS inputs
across four IO channels.
> diff --git a/drivers/phy/renesas/phy-rcar-gen5-mpphy.c b/drivers/phy/renesas/phy-rcar-gen5-mpphy.c
> new file mode 100644
> index 0000000000000..c096949477ca7
> --- /dev/null
> +++ b/drivers/phy/renesas/phy-rcar-gen5-mpphy.c
[ ... ]
> +static int mp_phy_reg_wait(struct mp_phy_priv *priv, u32 offs, u32 mask, u32 expected)
> +{
> + u32 val;
> + int ret;
> +
> + ret = regmap_read_poll_timeout(priv->map, offs, val,
> + (val & mask) == expected,
> + 0, 1000000);
> + if (ret) {
> + dev_err(priv->dev,
> + "Timeout waiting for offset: 0x%x, mask: 0x%x, expected: 0x%x\n",
> + offs, mask, expected);
> + }
> +
> + return ret;
> +}
[Severity: Medium]
Should regmap_read_poll_timeout() pass a non-zero sleep_us here? All
callers of mp_phy_reg_wait() run in sleeping process context via
phy_init() and phy_power_on(), so passing 0 makes poll_timeout_us()
busy-spin without sleeping for up to 1 second per call.
Also, in mp_phy_power_on_pcie4(), the second loop polling
MPPHY_PXSRAMCNT(id) for SRAM_INIT_DONE is redundant because
mp_phy_update_firmware_sram() in the preceding loop already waited for
SRAM_INIT_DONE on each channel.
> +
> +static void mp_phy_update_firmware(struct phy *phy)
> +{
> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
> +
> + for (int i = 0; i < priv->fw->size; i += 2) {
> + writew(get_unaligned_le16(priv->fw->data + i),
> + priv->base + MPPHY_FW_BASE + (MPPHY_FW_CH_OFFSET * phy->id) + i);
> + }
> +}
[ ... ]
> +static int mp_phy_init_pcie4(struct phy *phy)
> +{
> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
> +
> + if (phy->id != 0 && phy->id != 1) {
> + dev_err(priv->dev, "Invalid PHY ID for PCIe 0 or 1\n");
> + return -EINVAL;
> + }
> +
> + switch (priv->num_lanes[phy->id]) {
> + case 2:
> + if (phy->id == 0) {
> + mp_phy_init_pcie4_ch_req(priv, 0, 0, 0x2020201, 0x80004);
> + mp_phy_init_pcie4_ch_clk(priv, 0, 0);
> + mp_phy_init_pcie4_ch_rst(priv, 0, 0);
> + } else {
> + mp_phy_init_pcie4_ch_req(priv, 2, 2, 0x2020202, 0x8);
> + mp_phy_init_pcie4_ch_clk(priv, 2, 2);
> + mp_phy_init_pcie4_ch_rst(priv, 2, 2);
> + }
> + break;
> + case 4:
> + if (phy->id == 0) {
> + mp_phy_init_pcie4_ch_req(priv, 0, 1, 0x2020201, 0x80008);
> + mp_phy_init_pcie4_ch_clk(priv, 0, 1);
> + /* No reset pulse here. */
> + } else {
> + mp_phy_init_pcie4_ch_req(priv, 2, 3, 0x2020202, 0x8);
> + mp_phy_init_pcie4_ch_clk(priv, 2, 3);
> + mp_phy_init_pcie4_ch_rst(priv, 2, 3);
> + }
> + break;
> + case 8:
> + mp_phy_init_pcie4_ch_req(priv, 0, 0, 0x2020201, 0x8);
> + mp_phy_init_pcie4_ch_req(priv, 1, 3, 0x2020202, 0x8);
> + /* No clk settings here. */
> + mp_phy_init_pcie4_ch_rst(priv, 0, 3);
> + break;
> + default:
> + dev_err(priv->dev, "Invalid lane count for PCIe 0 or 1\n");
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
[Severity: High]
Does PCIe 1 initialization conflate the MP-PHY channel index (0 or 2) with
the PCIe controller index (0 or 1)?
In mp_phy_valid_configs[] and mp_phy_parse_dt(), PCIe 0 starts at channel
0 while PCIe 1 always starts at channel 2 (never channel 1, which is
either the second half of PCIe 0 x4/x8 or ETH.1), and priv->num_lanes[] is
a 2-element array indexed by PCIe controller 0 or 1. However,
mp_phy_init_pcie4(), mp_phy_power_on_pcie4(), and mp_phy_read_poll_pcie4()
require the channel ID to be 0 or 1, index priv->num_lanes[] with it, and
compute companion channels as (2 * id) + i. If PCIe 1 uses channel 2 in
DT, mp_phy_init_pcie4() rejects it with -EINVAL; if it uses channel 1,
mp_phy_xlate() returns priv->chan[1].phy, which is configured as
PHY_TYPE_XPCS in 6 of the 9 PCIe 1 configurations and powers on mpp1
instead of mpp2.
In addition, for x4 and x8 PCIe configurations spanning 2 or 4 channels,
mp_phy_init() and mp_phy_exit() only power on and off the single power
domain priv->pd_list->pd_devs[...] for the primary channel, leaving the
companion channels' power domains (mpp1..mpp3) unpowered while their
registers and SRAM are accessed.
[ ... ]
> +static int mp_phy_init(struct phy *phy)
> +{
> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
> + struct mp_phy_chan_priv *chan = &priv->chan[phy->id];
> + int ret;
> +
> + if (chan->initialized)
> + return 0;
> +
> + /*
> + * Note: Current source code support for Ethernet, PCIe initialization
> + * is based on the bare metal code shared by the board team.
> + */
> + ret = pm_runtime_get_sync(priv->pd_list->pd_devs[phy->id]);
> + if (ret < 0) {
> + dev_err(priv->dev,
> + "Failed to power on domain for channel %d: %d\n",
> + phy->id, ret);
> + return ret;
> + }
[Severity: High]
Can phy->id index out of bounds of priv->chan[] and
priv->pd_list->pd_devs[]?
phy_create() assigns phy->id from the global phy_ida in
drivers/phy/phy-core.c, not as a per-controller 0..3 channel index. If
any other PHY in the system is created before mp_phy_probe() runs (or
across driver unbind/rebind), phy->id will be >= MPPHY_NUM_CHANNELS (4),
causing out-of-bounds accesses on priv->chan[] and
priv->pd_list->pd_devs[] in mp_phy_init(), mp_phy_exit(), and
mp_phy_power_on(), as well as out-of-bounds MMIO writes in
mp_phy_update_firmware(). Storing the channel index in struct
mp_phy_chan_priv and passing &priv->chan[i] to phy_set_drvdata() would
avoid relying on phy->id.
[Severity: Medium]
Does the error path above also leak a runtime PM usage count on
priv->pd_list->pd_devs[...]? pm_runtime_get_sync() increments usage_count
even on failure, so returning without pm_runtime_put_noidle() (or using
pm_runtime_resume_and_get()) leaves the power domain reference leaked.
[ ... ]
> +static int mp_phy_power_on_usb(struct phy *phy)
> +{
> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
> + int ret;
> +
> + if (phy->id != 2 && phy->id != 3) {
> + dev_err(priv->dev, "Invalid PHY ID for USB 0 or 1\n");
> + return -EINVAL;
> + }
> +
> + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_PSTATE_1, 0x3, 0x3);
> + if (ret)
> + return ret;
> +
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_EN, 0x3);
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_TCPC, TCA_TCPC_VALID);
> + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1, 0x1);
> + if (ret)
> + return ret;
> +
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1503);
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_TCPC,
> + TCA_TCPC_VALID |
> + FIELD_PREP(TCA_TCPC_MUX_CONTRL,
> + TCA_TCPC_MUX_CONTRL_USB_CONN));
> + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1, 0x1);
> + if (ret)
> + return ret;
> +
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1503);
> +
> + return ret;
> +}
[Severity: High]
Does using regmap_set_bits() on TCA_INTR_STS and TCA_TCPC misprogram these
registers?
regmap_set_bits() performs a non-forced read-modify-write that skips the
bus write when the masked bits are already set and preserves all other
bits. On the write-1-to-clear TCA_INTR_STS register, if all bits in
0x1503 are already set, regmap_set_bits() skips the write and leaves bit 0
set so the second mp_phy_reg_wait() returns immediately without waiting;
if other W1C status bits are set, writing back the read value clears them
as well. On TCA_TCPC, regmap_set_bits() only ORs bits in without clearing
the multi-bit TCA_TCPC_MUX_CONTRL (GENMASK(2, 0)) field.
Similarly, in mp_phy_resume(), regmap_set_bits(priv->map, MPPHY_CMNCNT1,
priv->cmncnt[0]) is used instead of regmap_write(), which never clears 0
bits in the per-channel 2-bit protocol selectors (and skips the write
entirely when priv->cmncnt[0] is 0, such as for PCIe 0 x8).
[ ... ]
> +static int mp_phy_suspend_late(struct device *dev)
> +{
> + struct mp_phy_priv *priv = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = pm_runtime_force_suspend(dev);
> + if (ret) {
> + dev_err(dev, "Failed to force suspend\n");
> + return ret;
> + }
> +
> + ret = reset_control_assert(priv->reset_core);
> + if (ret) {
> + dev_err(dev, "Failed to assert PHY core reset\n");
> + return ret;
> + }
[Severity: Medium]
If reset_control_assert(priv->reset_core) fails here, does returning
without calling pm_runtime_force_resume(dev) leave runtime PM disabled on
dev? Because the PM core does not mark dev->power.is_late_suspended when
suspend_late fails, mp_phy_resume_early() will not run during suspend
recovery.
[ ... ]
> +static int mp_phy_probe(struct platform_device *pdev)
> +{
[ ... ]
> + ret = devm_pm_domain_attach_list(dev, &pd_attach_data, &priv->pd_list);
> + if (ret < 0)
> + return dev_err_probe(dev, ret, "Failed to attach power domains\n");
[Severity: Medium]
Can priv->pd_list be NULL or have fewer than MPPHY_NUM_CHANNELS entries
when devm_pm_domain_attach_list() returns >= 0?
devm_pm_domain_attach_list() returns the number of attached power domains
(and returns 0 without setting priv->pd_list when CONFIG_PM is disabled),
which would cause a NULL pointer dereference in mp_phy_init() when
accessing priv->pd_list->pd_devs[]. Should this check ret !=
MPPHY_NUM_CHANNELS?
> +
> + for (unsigned int i = 0; i < MPPHY_NUM_CHANNELS; i++) {
> + priv->chan[i].phy = devm_phy_create(dev, NULL, &mp_phy_ops);
> + if (IS_ERR(priv->chan[i].phy)) {
> + return dev_err_probe(dev, PTR_ERR(priv->chan[i].phy),
> + "Failed to create PHY %d\n", i);
> + }
> +
> + phy_set_drvdata(priv->chan[i].phy, priv);
> + }
> +
> + ret = mp_phy_resume_early(dev);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to resume PHY\n");
[Severity: Medium]
Does calling devm_phy_create() before runtime PM is enabled on dev prevent
phy_create() from enabling runtime PM on the child PHY devices?
In drivers/phy/phy-core.c, phy_create() only calls
pm_runtime_enable(&phy->dev) if pm_runtime_enabled(dev) is already true on
the parent. Moreover, mp_phy_resume_early() relies on
pm_runtime_force_resume(dev) to enable runtime PM, which returns -ENXIO
when CONFIG_PM_SLEEP is disabled, causing mp_phy_probe() to always fail on
!CONFIG_PM_SLEEP builds.
> +
> + ret = pm_runtime_get_sync(dev);
> + if (ret < 0) {
> + dev_err_probe(dev, ret, "Failed to get runtime PM\n");
> + goto err_resume;
> + }
> +
> + provider = devm_of_phy_provider_register(dev, mp_phy_xlate);
> + if (IS_ERR(provider)) {
> + ret = dev_err_probe(dev, PTR_ERR(provider),
> + "Failed to register PHY provider\n");
> + goto err_resume;
> + }
> +
> + return 0;
> +
> +err_resume:
> + mp_phy_suspend_late(dev);
> + return ret;
> +}
> +
> +static void mp_phy_remove(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> +
> + pm_runtime_get_sync(dev);
> +}
[Severity: High]
Does mp_phy_remove() call pm_runtime_get_sync(dev) instead of dropping the
runtime PM reference and suspending the hardware?
mp_phy_probe() already called mp_phy_resume_early(dev) and
pm_runtime_get_sync(dev), so calling pm_runtime_get_sync(dev) again in
mp_phy_remove() increments dev->power.usage_count to 2 and leaves
priv->clk_phy and priv->clk_core enabled and priv->reset_phy and
priv->reset_core deasserted when the driver unbinds. In addition, the
err_resume path in mp_phy_probe() never drops the usage_count increment
from pm_runtime_get_sync(dev) before calling mp_phy_suspend_late(dev).
> +
> +static const struct dev_pm_ops mp_phy_pm_ops = {
> + RUNTIME_PM_OPS(mp_phy_suspend, mp_phy_resume, NULL)
> + LATE_SYSTEM_SLEEP_PM_OPS(mp_phy_suspend_late, mp_phy_resume_early)
> +};
[Severity: High]
Does using LATE_SYSTEM_SLEEP_PM_OPS() break system suspend/resume ordering
with the R-Car Gen5 PCIe host controller and lose per-channel PHY state on
resume?
The R-Car PCIe controller driver (drivers/pci/controller/dwc/pcie-rcar-gen4.c)
uses DEFINE_NOIRQ_DEV_PM_OPS(). During suspend, mp_phy_suspend_late()
will assert the PHY resets and disable the PHY clocks before
rcar_gen4_pcie_suspend_noirq() stops the link and powers off the PHY;
during resume, rcar_gen4_pcie_resume_noirq() will call phy_init() and
phy_power_on() while the MP-PHY is still unclocked and in reset, after
which mp_phy_resume_early() -> mp_phy_resume() resets all channels and
wipes out their state. For consumers that do not call phy_exit() across
suspend, mp_phy_resume() also resets all channels while leaving
chan->initialized set to true, without reloading per-channel registers or
SRAM firmware.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201002008.413380-1-marek.vasut+renesas@mailbox.org?part=2
WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Marek Vasut" <marek.vasut+renesas@mailbox.org>,
linux-phy@lists.infradead.org
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
vkoul@kernel.org, neil.armstrong@linaro.org, olteanv@gmail.com,
wsa+renesas@sang-engineering.com
Subject: Re: [PATCH v3 2/3] phy: renesas: Add Renesas Multi-Protocol PHY driver for R-Car X5H
Date: Tue, 01 Dec 2026 00:34:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-242269@kernel.org> (raw)
In-Reply-To: <20261201002008.413380-2-marek.vasut+renesas@mailbox.org>
Thank you for your contribution! Sashiko AI review found 10 potential
issues to consider:
- [High] phy: renesas: out-of-bounds access using global phy->id as
channel index
- [High] phy: renesas: broken PCIe 1 channel mapping and multi-lane
power domains
- [High] phy: renesas: broken runtime PM and clock/reset cleanup in
probe and remove
- [High] phy: renesas: misuse of regmap_set_bits() on W1C and multi-bit
fields
- [High] phy: renesas: broken system sleep ordering and state loss on
resume
- [Medium] phy: renesas: runtime PM usage count leak on error in
mp_phy_init()
- [Medium] phy: renesas: broken runtime PM init in mp_phy_probe()
- [Medium] phy: renesas: NULL priv->pd_list dereference after
mp_phy_probe()
- [Medium] phy: renesas: missing runtime PM rollback in
mp_phy_suspend_late()
- [Medium] phy: renesas: busy-spin polling in mp_phy_reg_wait() and
duplicate SRAM wait
--
commit ad97b96dbe810225e507504cb6c802f2c347b4c9
Author: Thanh Quan <thanh.quan.xn@renesas.com>
phy: renesas: Add Renesas Multi-Protocol PHY driver for R-Car X5H
This commit adds a driver for the Renesas Multi-Protocol PHY on the R-Car
X5H (R8A78000) SoC, multiplexing PCIe4, USB 3.2, and Ethernet PCS inputs
across four IO channels.
> diff --git a/drivers/phy/renesas/phy-rcar-gen5-mpphy.c b/drivers/phy/renesas/phy-rcar-gen5-mpphy.c
> new file mode 100644
> index 0000000000000..c096949477ca7
> --- /dev/null
> +++ b/drivers/phy/renesas/phy-rcar-gen5-mpphy.c
[ ... ]
> +static int mp_phy_reg_wait(struct mp_phy_priv *priv, u32 offs, u32 mask, u32 expected)
> +{
> + u32 val;
> + int ret;
> +
> + ret = regmap_read_poll_timeout(priv->map, offs, val,
> + (val & mask) == expected,
> + 0, 1000000);
> + if (ret) {
> + dev_err(priv->dev,
> + "Timeout waiting for offset: 0x%x, mask: 0x%x, expected: 0x%x\n",
> + offs, mask, expected);
> + }
> +
> + return ret;
> +}
[Severity: Medium]
Should regmap_read_poll_timeout() pass a non-zero sleep_us here? All
callers of mp_phy_reg_wait() run in sleeping process context via
phy_init() and phy_power_on(), so passing 0 makes poll_timeout_us()
busy-spin without sleeping for up to 1 second per call.
Also, in mp_phy_power_on_pcie4(), the second loop polling
MPPHY_PXSRAMCNT(id) for SRAM_INIT_DONE is redundant because
mp_phy_update_firmware_sram() in the preceding loop already waited for
SRAM_INIT_DONE on each channel.
> +
> +static void mp_phy_update_firmware(struct phy *phy)
> +{
> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
> +
> + for (int i = 0; i < priv->fw->size; i += 2) {
> + writew(get_unaligned_le16(priv->fw->data + i),
> + priv->base + MPPHY_FW_BASE + (MPPHY_FW_CH_OFFSET * phy->id) + i);
> + }
> +}
[ ... ]
> +static int mp_phy_init_pcie4(struct phy *phy)
> +{
> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
> +
> + if (phy->id != 0 && phy->id != 1) {
> + dev_err(priv->dev, "Invalid PHY ID for PCIe 0 or 1\n");
> + return -EINVAL;
> + }
> +
> + switch (priv->num_lanes[phy->id]) {
> + case 2:
> + if (phy->id == 0) {
> + mp_phy_init_pcie4_ch_req(priv, 0, 0, 0x2020201, 0x80004);
> + mp_phy_init_pcie4_ch_clk(priv, 0, 0);
> + mp_phy_init_pcie4_ch_rst(priv, 0, 0);
> + } else {
> + mp_phy_init_pcie4_ch_req(priv, 2, 2, 0x2020202, 0x8);
> + mp_phy_init_pcie4_ch_clk(priv, 2, 2);
> + mp_phy_init_pcie4_ch_rst(priv, 2, 2);
> + }
> + break;
> + case 4:
> + if (phy->id == 0) {
> + mp_phy_init_pcie4_ch_req(priv, 0, 1, 0x2020201, 0x80008);
> + mp_phy_init_pcie4_ch_clk(priv, 0, 1);
> + /* No reset pulse here. */
> + } else {
> + mp_phy_init_pcie4_ch_req(priv, 2, 3, 0x2020202, 0x8);
> + mp_phy_init_pcie4_ch_clk(priv, 2, 3);
> + mp_phy_init_pcie4_ch_rst(priv, 2, 3);
> + }
> + break;
> + case 8:
> + mp_phy_init_pcie4_ch_req(priv, 0, 0, 0x2020201, 0x8);
> + mp_phy_init_pcie4_ch_req(priv, 1, 3, 0x2020202, 0x8);
> + /* No clk settings here. */
> + mp_phy_init_pcie4_ch_rst(priv, 0, 3);
> + break;
> + default:
> + dev_err(priv->dev, "Invalid lane count for PCIe 0 or 1\n");
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
[Severity: High]
Does PCIe 1 initialization conflate the MP-PHY channel index (0 or 2) with
the PCIe controller index (0 or 1)?
In mp_phy_valid_configs[] and mp_phy_parse_dt(), PCIe 0 starts at channel
0 while PCIe 1 always starts at channel 2 (never channel 1, which is
either the second half of PCIe 0 x4/x8 or ETH.1), and priv->num_lanes[] is
a 2-element array indexed by PCIe controller 0 or 1. However,
mp_phy_init_pcie4(), mp_phy_power_on_pcie4(), and mp_phy_read_poll_pcie4()
require the channel ID to be 0 or 1, index priv->num_lanes[] with it, and
compute companion channels as (2 * id) + i. If PCIe 1 uses channel 2 in
DT, mp_phy_init_pcie4() rejects it with -EINVAL; if it uses channel 1,
mp_phy_xlate() returns priv->chan[1].phy, which is configured as
PHY_TYPE_XPCS in 6 of the 9 PCIe 1 configurations and powers on mpp1
instead of mpp2.
In addition, for x4 and x8 PCIe configurations spanning 2 or 4 channels,
mp_phy_init() and mp_phy_exit() only power on and off the single power
domain priv->pd_list->pd_devs[...] for the primary channel, leaving the
companion channels' power domains (mpp1..mpp3) unpowered while their
registers and SRAM are accessed.
[ ... ]
> +static int mp_phy_init(struct phy *phy)
> +{
> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
> + struct mp_phy_chan_priv *chan = &priv->chan[phy->id];
> + int ret;
> +
> + if (chan->initialized)
> + return 0;
> +
> + /*
> + * Note: Current source code support for Ethernet, PCIe initialization
> + * is based on the bare metal code shared by the board team.
> + */
> + ret = pm_runtime_get_sync(priv->pd_list->pd_devs[phy->id]);
> + if (ret < 0) {
> + dev_err(priv->dev,
> + "Failed to power on domain for channel %d: %d\n",
> + phy->id, ret);
> + return ret;
> + }
[Severity: High]
Can phy->id index out of bounds of priv->chan[] and
priv->pd_list->pd_devs[]?
phy_create() assigns phy->id from the global phy_ida in
drivers/phy/phy-core.c, not as a per-controller 0..3 channel index. If
any other PHY in the system is created before mp_phy_probe() runs (or
across driver unbind/rebind), phy->id will be >= MPPHY_NUM_CHANNELS (4),
causing out-of-bounds accesses on priv->chan[] and
priv->pd_list->pd_devs[] in mp_phy_init(), mp_phy_exit(), and
mp_phy_power_on(), as well as out-of-bounds MMIO writes in
mp_phy_update_firmware(). Storing the channel index in struct
mp_phy_chan_priv and passing &priv->chan[i] to phy_set_drvdata() would
avoid relying on phy->id.
[Severity: Medium]
Does the error path above also leak a runtime PM usage count on
priv->pd_list->pd_devs[...]? pm_runtime_get_sync() increments usage_count
even on failure, so returning without pm_runtime_put_noidle() (or using
pm_runtime_resume_and_get()) leaves the power domain reference leaked.
[ ... ]
> +static int mp_phy_power_on_usb(struct phy *phy)
> +{
> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
> + int ret;
> +
> + if (phy->id != 2 && phy->id != 3) {
> + dev_err(priv->dev, "Invalid PHY ID for USB 0 or 1\n");
> + return -EINVAL;
> + }
> +
> + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_PSTATE_1, 0x3, 0x3);
> + if (ret)
> + return ret;
> +
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_EN, 0x3);
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_TCPC, TCA_TCPC_VALID);
> + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1, 0x1);
> + if (ret)
> + return ret;
> +
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1503);
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_TCPC,
> + TCA_TCPC_VALID |
> + FIELD_PREP(TCA_TCPC_MUX_CONTRL,
> + TCA_TCPC_MUX_CONTRL_USB_CONN));
> + ret = mp_phy_reg_wait(priv, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1, 0x1);
> + if (ret)
> + return ret;
> +
> + regmap_set_bits(priv->map, TCA_OFFSET(phy->id) + TCA_INTR_STS, 0x1503);
> +
> + return ret;
> +}
[Severity: High]
Does using regmap_set_bits() on TCA_INTR_STS and TCA_TCPC misprogram these
registers?
regmap_set_bits() performs a non-forced read-modify-write that skips the
bus write when the masked bits are already set and preserves all other
bits. On the write-1-to-clear TCA_INTR_STS register, if all bits in
0x1503 are already set, regmap_set_bits() skips the write and leaves bit 0
set so the second mp_phy_reg_wait() returns immediately without waiting;
if other W1C status bits are set, writing back the read value clears them
as well. On TCA_TCPC, regmap_set_bits() only ORs bits in without clearing
the multi-bit TCA_TCPC_MUX_CONTRL (GENMASK(2, 0)) field.
Similarly, in mp_phy_resume(), regmap_set_bits(priv->map, MPPHY_CMNCNT1,
priv->cmncnt[0]) is used instead of regmap_write(), which never clears 0
bits in the per-channel 2-bit protocol selectors (and skips the write
entirely when priv->cmncnt[0] is 0, such as for PCIe 0 x8).
[ ... ]
> +static int mp_phy_suspend_late(struct device *dev)
> +{
> + struct mp_phy_priv *priv = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = pm_runtime_force_suspend(dev);
> + if (ret) {
> + dev_err(dev, "Failed to force suspend\n");
> + return ret;
> + }
> +
> + ret = reset_control_assert(priv->reset_core);
> + if (ret) {
> + dev_err(dev, "Failed to assert PHY core reset\n");
> + return ret;
> + }
[Severity: Medium]
If reset_control_assert(priv->reset_core) fails here, does returning
without calling pm_runtime_force_resume(dev) leave runtime PM disabled on
dev? Because the PM core does not mark dev->power.is_late_suspended when
suspend_late fails, mp_phy_resume_early() will not run during suspend
recovery.
[ ... ]
> +static int mp_phy_probe(struct platform_device *pdev)
> +{
[ ... ]
> + ret = devm_pm_domain_attach_list(dev, &pd_attach_data, &priv->pd_list);
> + if (ret < 0)
> + return dev_err_probe(dev, ret, "Failed to attach power domains\n");
[Severity: Medium]
Can priv->pd_list be NULL or have fewer than MPPHY_NUM_CHANNELS entries
when devm_pm_domain_attach_list() returns >= 0?
devm_pm_domain_attach_list() returns the number of attached power domains
(and returns 0 without setting priv->pd_list when CONFIG_PM is disabled),
which would cause a NULL pointer dereference in mp_phy_init() when
accessing priv->pd_list->pd_devs[]. Should this check ret !=
MPPHY_NUM_CHANNELS?
> +
> + for (unsigned int i = 0; i < MPPHY_NUM_CHANNELS; i++) {
> + priv->chan[i].phy = devm_phy_create(dev, NULL, &mp_phy_ops);
> + if (IS_ERR(priv->chan[i].phy)) {
> + return dev_err_probe(dev, PTR_ERR(priv->chan[i].phy),
> + "Failed to create PHY %d\n", i);
> + }
> +
> + phy_set_drvdata(priv->chan[i].phy, priv);
> + }
> +
> + ret = mp_phy_resume_early(dev);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to resume PHY\n");
[Severity: Medium]
Does calling devm_phy_create() before runtime PM is enabled on dev prevent
phy_create() from enabling runtime PM on the child PHY devices?
In drivers/phy/phy-core.c, phy_create() only calls
pm_runtime_enable(&phy->dev) if pm_runtime_enabled(dev) is already true on
the parent. Moreover, mp_phy_resume_early() relies on
pm_runtime_force_resume(dev) to enable runtime PM, which returns -ENXIO
when CONFIG_PM_SLEEP is disabled, causing mp_phy_probe() to always fail on
!CONFIG_PM_SLEEP builds.
> +
> + ret = pm_runtime_get_sync(dev);
> + if (ret < 0) {
> + dev_err_probe(dev, ret, "Failed to get runtime PM\n");
> + goto err_resume;
> + }
> +
> + provider = devm_of_phy_provider_register(dev, mp_phy_xlate);
> + if (IS_ERR(provider)) {
> + ret = dev_err_probe(dev, PTR_ERR(provider),
> + "Failed to register PHY provider\n");
> + goto err_resume;
> + }
> +
> + return 0;
> +
> +err_resume:
> + mp_phy_suspend_late(dev);
> + return ret;
> +}
> +
> +static void mp_phy_remove(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> +
> + pm_runtime_get_sync(dev);
> +}
[Severity: High]
Does mp_phy_remove() call pm_runtime_get_sync(dev) instead of dropping the
runtime PM reference and suspending the hardware?
mp_phy_probe() already called mp_phy_resume_early(dev) and
pm_runtime_get_sync(dev), so calling pm_runtime_get_sync(dev) again in
mp_phy_remove() increments dev->power.usage_count to 2 and leaves
priv->clk_phy and priv->clk_core enabled and priv->reset_phy and
priv->reset_core deasserted when the driver unbinds. In addition, the
err_resume path in mp_phy_probe() never drops the usage_count increment
from pm_runtime_get_sync(dev) before calling mp_phy_suspend_late(dev).
> +
> +static const struct dev_pm_ops mp_phy_pm_ops = {
> + RUNTIME_PM_OPS(mp_phy_suspend, mp_phy_resume, NULL)
> + LATE_SYSTEM_SLEEP_PM_OPS(mp_phy_suspend_late, mp_phy_resume_early)
> +};
[Severity: High]
Does using LATE_SYSTEM_SLEEP_PM_OPS() break system suspend/resume ordering
with the R-Car Gen5 PCIe host controller and lose per-channel PHY state on
resume?
The R-Car PCIe controller driver (drivers/pci/controller/dwc/pcie-rcar-gen4.c)
uses DEFINE_NOIRQ_DEV_PM_OPS(). During suspend, mp_phy_suspend_late()
will assert the PHY resets and disable the PHY clocks before
rcar_gen4_pcie_suspend_noirq() stops the link and powers off the PHY;
during resume, rcar_gen4_pcie_resume_noirq() will call phy_init() and
phy_power_on() while the MP-PHY is still unclocked and in reset, after
which mp_phy_resume_early() -> mp_phy_resume() resets all channels and
wipes out their state. For consumers that do not call phy_exit() across
suspend, mp_phy_resume() also resets all channels while leaving
chan->initialized set to true, without reloading per-channel registers or
SRAM firmware.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201002008.413380-1-marek.vasut+renesas@mailbox.org?part=2
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-12-01 0:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 0:19 [PATCH v3 1/3] dt-bindings: phy: Document Renesas Multi-Protocol PHY driver for R-Car X5H Marek Vasut
2026-12-01 0:19 ` Marek Vasut
2026-12-01 0:19 ` [PATCH v3 2/3] phy: renesas: Add " Marek Vasut
2026-12-01 0:19 ` Marek Vasut
2026-12-01 0:34 ` sashiko-bot [this message]
2026-12-01 0:34 ` sashiko-bot
2026-12-01 0:19 ` [PATCH v3 3/3] phy: renesas: rcar-gen5-mpphy: Document how to obtain firmware Marek Vasut
2026-12-01 0:19 ` Marek Vasut
2026-12-01 0:32 ` [PATCH v3 1/3] dt-bindings: phy: Document Renesas Multi-Protocol PHY driver for R-Car X5H sashiko-bot
2026-12-01 0:32 ` 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=sashiko-outbox-242269@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=marek.vasut+renesas@mailbox.org \
--cc=neil.armstrong@linaro.org \
--cc=olteanv@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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.