From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796085246; b=wllDC5p41jIaQjVQIiALaKf11Tzno3ASt3JBTuPviJVut/GcrDCR65YvHo+rF+7Yxj28 +JtwsCCPKDWpPuqbv9WAS7DC4/OjeezHmoL8E1MCR7lhb3Wgxx+FTPGru9H29nZCBrlZP tTNdxUlNIkWs07Ou13fYa42LchqLnmqz1Ji8nPTxQclnyRFCLyhHF5+YoA6H5+Mv/kBYO bXzGy68iby8hy0iNy3osIbQSbOoOYUftBRHvB2bfmZ7m0GJJrShHyLV76N6h/6sNVUpaR 2dpshPHHDO6sn7ru3+FRHF72//NwSBxFB1whydB7UE++VkAt04ewc3Y/ria5uvDjDpQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796085246; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=TFyYVOkLnsbCzfkNFuOkT1Ap8QpBYyofcLJpQXozs5E=; b=Vzsw9bAz6eq9Y5usk55Ba/pF0b2PKVdiyR4FLIvw8Pl73s70zQ5smmWESQofIK4IejPz 1Yq1JkeywMyKVyUOEMS6TvVzmPOQugelhYGzP5iJdabSdmSsiyas4vPJQeuMaSaCw7l2R MNuqt+YTQEUzaPGIvBAwRw/lFgcvJHehI9jzqHRqQUi0slhSjUOaVzxJxQzvFNjg160vg wIEluRjBcv7zO42QhQ2uxoE+UQFmtqyC7ZZHt34Ra8w+qjap7TkVQODV1m2hC/KsXtwA4 34bhW5RK9noDV3r7QfhA7o4tvpc+qzSIm7XegVrnmKSoK35fCHTomxA8TjXOsEl6ebg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CZJOhEG+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7072E606A31A for ; Tue, 1 Dec 2026 00:34:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CZJOhEG+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD5A01F000C1; Tue, 1 Dec 2026 00:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796085246; bh=TFyYVOkLnsbCzfkNFuOkT1Ap8QpBYyofcLJpQXozs5E=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CZJOhEG+sIRmnROkGtHO0LCygClP7GJ2tzsGVog5gD66XF6tBjWHjtII4VqttZk7D LZj190Lpgzvrtsy52W3zQ7UnywUgF30ZnOZAy2gdKXgq/vk67icnQAcLZwA92EuE6b Bcd6Fy8qPuecmdoDhCPgUgXXPqDAYne2WPheDbQ+O6A99leyCKUZ36YD5p5+evh6bB 3CeeftG4AjZTgXk5zCqWHbITzGLOqjFD4B0BJdX4IrbVRw5wnzKXZVAy7QlO6PeVeB fw3UXStFntqGm7yEIgoqocfO1+IMPSgTKJX+hVyNzEfTzgc3UfNd3zIWJx2h9EWwZh lyJy3v/UpGTtw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 2/3] phy: renesas: Add Renesas Multi-Protocol PHY driver for R-Car X5H Reply-To: sashiko-reviews@lists.linux.dev To: "Marek Vasut" , 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 In-Reply-To: <20261201002008.413380-2-marek.vasut+renesas@mailbox.org> References: <20261201002008.413380-1-marek.vasut+renesas@mailbox.org> <20261201002008.413380-2-marek.vasut+renesas@mailbox.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 00:34:05 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/rene= sas/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 =3D regmap_read_poll_timeout(priv->map, offs, val, > + (val & mask) =3D=3D 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 =3D phy_get_drvdata(phy); > + > + for (int i =3D 0; i < priv->fw->size; i +=3D 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 =3D phy_get_drvdata(phy); > + > + if (phy->id !=3D 0 && phy->id !=3D 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 =3D=3D 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 =3D=3D 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 =3D phy_get_drvdata(phy); > + struct mp_phy_chan_priv *chan =3D &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 =3D 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 >=3D 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 =3D phy_get_drvdata(phy); > + int ret; > + > + if (phy->id !=3D 2 && phy->id !=3D 3) { > + dev_err(priv->dev, "Invalid PHY ID for USB 0 or 1\n"); > + return -EINVAL; > + } > + > + ret =3D 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_VAL= ID); > + ret =3D 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 =3D 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 =3D dev_get_drvdata(dev); > + int ret; > + > + ret =3D pm_runtime_force_suspend(dev); > + if (ret) { > + dev_err(dev, "Failed to force suspend\n"); > + return ret; > + } > + > + ret =3D 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 =3D 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 >=3D 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 !=3D MPPHY_NUM_CHANNELS? > + > + for (unsigned int i =3D 0; i < MPPHY_NUM_CHANNELS; i++) { > + priv->chan[i].phy =3D 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 =3D 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 =3D pm_runtime_get_sync(dev); > + if (ret < 0) { > + dev_err_probe(dev, ret, "Failed to get runtime PM\n"); > + goto err_resume; > + } > + > + provider =3D devm_of_phy_provider_register(dev, mp_phy_xlate); > + if (IS_ERR(provider)) { > + ret =3D 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 =3D &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 =3D { > + 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201002008.4133= 80-1-marek.vasut+renesas@mailbox.org?part=3D2