All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Robin <benjamin.robin@bootlin.com>
To: sashiko-reviews@lists.linux.dev
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-phy@lists.infradead.org, robh@kernel.org,
	conor+dt@kernel.org, vkoul@kernel.org, neil.armstrong@linaro.org,
	olteanv@gmail.com
Subject: Re: [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver
Date: Wed, 02 Dec 2026 18:18:20 +0100	[thread overview]
Message-ID: <lbqIPw3eTcKROZQUbD6PdA@bootlin.com> (raw)
In-Reply-To: <sashiko-outbox-246119@kernel.org>

On Wednesday, December 2, 2026 at 4:38 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 8 potential
> issues to consider:
> - [High] phy: cadence-torrent: broken QSGMII mode check in
>   tp_add_phy_from_of_subnode()
> - [High] phy: cadence-torrent: divide-by-zero in tp_dp_update_pll_freq()
> - [High] phy: cadence-torrent: NULL dereference of base in
>   tp_dp_find_used_lanes()
> - [High] phy: cadence-torrent: A3 timeout on unused DP lanes and partial
>   lane config
> - [High] phy: cadence-torrent: NULL deref, div-by-zero, and reset bug if
>   preconfigured
> - [Medium] phy: cadence-torrent: wrong std1 initialization in
>   tp_calc_pll_fb_div_modes()
> - [Medium] phy: cadence-torrent: broken dual-refclk validation in
>   tp_ref_clk_init()
> - [Medium] phy: cadence-torrent: rejected standard swap with clk1 in
>   tp_find_link_cfg()
> --
> 
> commit 107a7c6a980951f00c775c6427a095f0f4912099
> Author: Benjamin Robin <benjamin.robin@bootlin.com>
> 
> phy: cadence-torrent: rewrite Torrent PHY driver
> 
> This commit rewrites the Cadence Torrent PHY driver to compute reference
> clock and PLL register values at run time and select protocol, revision,
> and process-node settings from compact configuration tables instead of
> hard-coded register arrays.
> 
> > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> > index 7c4c20b005a95..21ad6c30a3f20 100644
> > --- a/drivers/phy/cadence/phy-cadence-torrent.c
> > +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> 
> [ ... ]
> 
> > +static void tp_calc_pll_fb_div_modes(struct tp_data *tp_data)
> > +		if ((std0->flags & STD_FLAG_PCIE_ML) || std1->type == STD_TYPE_NONE)
> > +			tp_data->plls[PLL1_MODE0].fb_div_mode = div_mode;
> > +		else
> > +			tp_data->plls[PLL1_MODE0].fb_div_mode = PLL_FB_DIV_MODE_FBR;
> 
> [Severity: Medium]
> Should std1 be initialized to &tp_data->standards[1] instead of
> &tp_data->standards[0]?
> 
> Because std1 points to standards[0], std1->type == STD_TYPE_NONE is always
> false inside the std0->type == STD_TYPE_PCIE branch, so single-link PCIe
> configurations set plls[PLL1_MODE0].fb_div_mode to PLL_FB_DIV_MODE_FBR
> instead of div_mode.

This is indeed a bug, and will be fixed in v3.

> [ ... ]
> 
> > +static int tp_dp_update_pll_freq(struct tp_data *tp_data, const struct tp_link *link,
> > +				 enum tp_pll_id pll_id, u32 bit_rate, bool ssc)
> >  {
> > -	struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> > -
> > -	tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0);
> > -	tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1);
> > -	tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 0);
> > +	const struct tp_link_cfg *link_cfg = tp_data->link_cfg;
> > +	struct tp_pll_data *pll = &tp_data->plls[pll_id];
> > +	u32 pll_freq_khz = 0;
> > +	u16 val;
> >  
> > -	return 0;
> > -}
> > +	if (link_cfg->pll_freq[pll_id] != PLL_DP)
> > +		return -EINVAL;
> >  
> > -static void tp_refclk_driver_disable(struct clk_hw *hw)
> > -{
> > -	struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> > +	pll_freq_khz = tp_dp_pll_freq_from_bit_rate(bit_rate);
> > +	if (pll_freq_khz == 0)
> > +		return -EINVAL;
> >  
> > -	tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1);
> > -}
> > +	pll->freq_khz = pll_freq_khz;
> > +	pll->ssc = ssc;
> > +	pll->fractional_mode = tp_is_pll_fractional_mode_required(pll);
> >  
> > -static int tp_refclk_driver_is_enabled(struct clk_hw *hw)
> > -{
> > -	struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> > -	u16 val;
> > +	val = tp_dp_pll_clk_sel_from_bit_rate(bit_rate);
> > +	tp_reg_write(&tp_data->reg_common_cdb, CMN_PDIAG_PLLx_CLK_SEL_Mx(pll_id), val);
> >  
> > -	val = tp_reg_field_read(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1]);
> > -	return !val;
> > -}
> > +	val = tp_dp_xcvr_diag_hsclk_div_from_bit_rate(bit_rate);
> > +	tp_write_lanes_reg(tp_data->reg_tx_lane_cdb, link->mlane, link->max_lanes,
> > +			   XCVR_DIAG_HSCLK_DIV, val);
> >  
> > -static u8 tp_refclk_driver_get_parent(struct clk_hw *hw)
> > -{
> > -	struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> > -	u16 val;
> > +	tp_write_pll_lock_tmr(tp_data, pll_id);
> > +	tp_write_pll_regs(tp_data, pll_id);
> 
> [Severity: High]
> Can tp_dp_update_pll_freq() divide by zero when tp_data->already_configured
> was true at probe time?
> 
> When tp_data->already_configured is true, cdns_torrent_phy_probe() skips
> both tp_ref_clks_init() and tp_configure_links() (and tp_resume_noirq()
> also skips tp_configure_links() -> tp_init_plls_data() if nb_phy_on > 0 and
> the PHY remained configured), leaving tp_data->ref_clk_khz and
> pll->ref_clk_khz at 0.  Calling phy_configure() with opts->dp.set_rate set
> then reaches tp_dp_update_pll_freq(), where
> tp_is_pll_fractional_mode_required() and tp_write_pll_regs() divide by
> pll->ref_clk_khz.

This is indeed a bug. Previously the configuration was completely disabled.
In the v3 the rate configuration will only be allowed if the reference clock
was initialized.
 
> [ ... ]
> 
> > +/* Configure link rate as required. */
> > +static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link,
> > +			  const struct phy_configure_opts_dp *dp)
> > +{
> > +	int ret;
> >  
> > -static const struct cdns_torrent_vals usb_sgmii_xcvr_diag_ln_vals = {
> > -	.reg_pairs = usb_sgmii_xcvr_diag_ln_regs,
> > -	.num_regs = ARRAY_SIZE(usb_sgmii_xcvr_diag_ln_regs),
> > -};
> > +	ret = tp_dptx_set_power_state(tp_data, link->mlane, link->max_lanes, POWERSTATE_A3);
> > +	if (ret)
> > +		return ret;
> 
> [Severity: High]
> Does tp_dptx_set_power_state() time out here when reconfiguring the link
> rate while link->num_lanes < link->max_lanes?
> 
> When fewer than link->max_lanes lanes are active (for example 1 or 2 lanes
> on a 4-lane DP link) and phy_configure() updates the link rate without
> changing the lane count, the active lanes are in POWERSTATE_A0 while unused
> lanes are held in reset with PHY_PMA_XCVR_PLLCLK_EN cleared.  Passing
> link->max_lanes to tp_dptx_set_power_state() causes (read_val & mask) to be
> non-zero, and readl_poll_timeout() then waits for the reset lanes to
> acknowledge POWERSTATE_A3 in PHY_PMA_XCVR_POWER_STATE_ACK and fails with
> -ETIMEDOUT.
> 
> In addition, tp_configure_links() programs per-lane CDB registers only up
> to link->num_lanes instead of link->max_lanes, which leaves upper lanes
> unconfigured after a suspend/resume cycle if the lane count is later
> increased.

This might be an issue. In v3 for the lanes in reset, do not try to go to
POWERSTATE_A3 (ask 0), so it should fix the issue.
 
> [ ... ]
> 
> > +static int tp_phy_on(struct phy *phy)
> > +{
> > +	struct tp_link *link = phy_get_drvdata(phy);
> > +	struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
> > +	u16 val;
> > +	int ret;
> >  
> > -static const struct cdns_torrent_vals pcie_sgmii_xcvr_diag_ln_vals = {
> > -	.reg_pairs = pcie_sgmii_xcvr_diag_ln_regs,
> > -	.num_regs = ARRAY_SIZE(pcie_sgmii_xcvr_diag_ln_regs),
> > -};
> > +	guard(mutex)(&tp_data->lock);
> >  
> > -static const struct cdns_torrent_vals sgmii_pcie_xcvr_diag_ln_vals = {
> > -	.reg_pairs = sgmii_pcie_xcvr_diag_ln_regs,
> > -	.num_regs = ARRAY_SIZE(sgmii_pcie_xcvr_diag_ln_regs),
> > -};
> > +	if (tp_data->already_configured) {
> > +		/* Give 5ms to 10ms delay for the PIPE clock to be stable */
> > +		usleep_range(5000, 10000);
> > +		tp_data->nb_phy_on++;
> > +		return 0;
> > +	}
> 
> [ ... ]
> 
> > +static int tp_phy_off(struct phy *phy)
> > +{
> > +	struct tp_link *link = phy_get_drvdata(phy);
> > +	struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
> > +	int ret;
> >  
> > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_cmn_vals = {
> > -	.reg_pairs = qsgmii_100_no_ssc_cmn_regs,
> > -	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_cmn_regs),
> > -};
> > +	guard(mutex)(&tp_data->lock);
> >  
> > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_tx_ln_vals = {
> > -	.reg_pairs = qsgmii_100_no_ssc_tx_ln_regs,
> > -	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_tx_ln_regs),
> > -};
> > +	ret = tp_control_link_reset(link, true);
> > +	if (ret)
> > +		return ret;
> >  
> > -static const struct cdns_torrent_vals ti_qsgmii_100_no_ssc_tx_ln_vals = {
> > -	.reg_pairs = ti_qsgmii_100_no_ssc_tx_ln_regs,
> > -	.num_regs = ARRAY_SIZE(ti_qsgmii_100_no_ssc_tx_ln_regs),
> > -};
> > +	if (tp_data->nb_phy_on == 1) {
> > +		ret = reset_control_assert(tp_data->phy_rst);
> > +		if (ret)
> > +			return ret;
> > +	}
> >  
> > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_rx_ln_vals = {
> > -	.reg_pairs = qsgmii_100_no_ssc_rx_ln_regs,
> > -	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_rx_ln_regs),
> > -};
> > +	tp_data->nb_phy_on--;
> > +	return 0;
> > +}
> 
> [Severity: High]
> What happens if a pre-configured PHY (tp_data->already_configured == true)
> is powered off and then powered back on?
> 
> tp_phy_off() asserts link->lnk_rst and tp_data->phy_rst without clearing
> tp_data->already_configured, so a subsequent tp_phy_on() takes the early
> already_configured return and leaves both resets asserted and the PHY
> unconfigured.  In addition, when tp_data->already_configured is true at
> probe time, tp_dp_find_used_lanes() dereferences tp_data->base while it is
> still NULL and tp_dp_update_pll_freq() divides by zero because
> ref_clk_khz is never initialized.

This might be an issue. In v3 if already_configured then the resets will be
controlled normally from tp_phy_on().

The NULL dereference is indeed a bug. To fix it tp_dp_reg_base_init() will
be called earlier in the probe.

> [ ... ]
> 
> > +static int tp_ref_clk_init(const struct tp_data *tp_data, struct clk *clk, const char *name,
> > +			   u32 *p_ref_clk_khz)
> > +{
> > +	struct device *dev = tp_data->dev;
> > +	u32 ref_clk_rate;
> > +	int ret;
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_SGMII, NO_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> > +	ret = clk_prepare_enable(clk);
> > +	if (ret) {
> > +		dev_err(dev, "Failed to prepare %s ref clock: %d\n", name, ret);
> > +		return ret;
> > +	}
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, NO_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, EXTERNAL_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, INTERNAL_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> > +	ref_clk_rate = clk_get_rate(clk);
> > +	if (!ref_clk_rate) {
> > +		dev_err(dev, "Failed to get %s ref clock rate\n", name);
> > +		ret = -EINVAL;
> > +		goto disable_clk;
> > +	}
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, NO_SSC), &usb_100_no_ssc_rx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, EXTERNAL_SSC), &usb_100_no_ssc_rx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, INTERNAL_SSC), &usb_100_no_ssc_rx_ln_vals},
> > +	for (u8 i = 0; i < tp_data->nb_links; ++i) {
> > +		if (!tp_is_ref_freq_supported(tp_data->links[i].type, ref_clk_rate)) {
> > +			dev_err(dev, "Invalid ref clock rate: %u Hz\n", ref_clk_rate);
> > +			ret = -EINVAL;
> > +			goto disable_clk;
> > +		}
> > +	}
> 
> [Severity: Medium]
> Does validating ref_clk_rate against all links in tp_data->links[] reject
> valid dual-reference-clock configurations?
> 
> When both refclk (PLL0) and pll1_refclk (PLL1) are provided,
> tp_ref_clks_init() calls tp_ref_clk_init() for each clock, and this loop
> requires both frequencies to be supported by every link's standard.  A
> setup such as SATA at 100 MHz on PLL0 with USXGMII at 156.25 MHz on PLL1
> fails probe with -EINVAL because 156.25 MHz is not in SATA's supported
> frequency list (freq_set4).

I largely agree with this remark, but this is the current behavior of the
Cadence "Torrent Programmers Guide" spreadsheet. So for now, keep the same
behavior as documented by Cadence, but that seems a bit strange.

> [ ... ]
> 
> > +	switch (phy_type) {
> > +	case PHY_TYPE_PCIE:
> > +		std_type = STD_TYPE_PCIE;
> > +		break;
> > +	case PHY_TYPE_USB3:
> > +		std_type = STD_TYPE_USB_TXRX;
> > +		supported_flags = CDNS_TORRENT_MODE_USB_G1 | CDNS_TORRENT_MODE_USB_IO_11V;
> > +		break;
> > +	case PHY_TYPE_DP:
> > +		std_type = STD_TYPE_DP;
> > +		break;
> > +	case PHY_TYPE_XAUI:
> > +		std_type = STD_TYPE_XAUI;
> > +		supported_flags = CDNS_TORRENT_MODE_XAUI_LP;
> > +		break;
> > +	case PHY_TYPE_SGMII:
> > +		std_type = STD_TYPE_SGMII;
> > +		supported_flags = CDNS_TORRENT_MODE_2500_BASEX;
> > +		break;
> > +	case PHY_TYPE_QSGMII:
> > +		std_type = STD_TYPE_SGMII;
> > +		link_flags |= STD_FLAG_QSGMII;
> > +		break;
> > +	case PHY_TYPE_SATA:
> > +		std_type = STD_TYPE_SATA;
> > +		supported_flags = CDNS_TORRENT_MODE_SATA_LP;
> > +		break;
> > +	case PHY_TYPE_USXGMII:
> > +		std_type = STD_TYPE_USXGMII;
> > +		break;
> > +	default:
> > +		dev_err(dev, "Unsupported protocol: %u\n", phy_type);
> > +		return -EINVAL;
> > +	}
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, EXTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, INTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> > +	if (link_flags & ~supported_flags) {
> > +		dev_err(dev, "Unsupported modes 0x%X for this PHY type %u\n",
> > +			link_flags, std_type);
> > +		return -EINVAL;
> > +	}
> 
> [Severity: High]
> Does PHY_TYPE_QSGMII always fail this check with -EINVAL?
> 
> The PHY_TYPE_QSGMII case sets STD_FLAG_QSGMII in link_flags while leaving
> supported_flags at 0, so (link_flags & ~supported_flags) is always
> non-zero.

This is indeed a bug introduced while refactoring and removing the QSGMII flag
from dt-bindings. This will be fixed in v3.
 
> [ ... ]
> 
> > +	link_cfg = tp_find_link_cfg_from_standards(std0, std1);
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, NO_SSC), &usb_100_no_ssc_cmn_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, EXTERNAL_SSC), &usb_100_no_ssc_cmn_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, INTERNAL_SSC), &usb_100_no_ssc_cmn_vals},
> > +	/* Only swap the two standards if PLL1 has no dedicated reference clock. If
> > +	 * there are two DTS PHY nodes and the `pll1_refclk` reference clock is
> > +	 * specified, the user assumes the PLL1 reference clock will be used for the
> > +	 * second DTS PHY node. If the standards are swapped, this clock would be used
> > +	 * for the first DTS PHY node instead, which could be a problem, for example
> > +	 * with USXGMII, which prefers a 156.25 MHz reference clock.
> > +	 */
> > +	if (!link_cfg && !tp_data->clk1) {
> > +		link_cfg = tp_find_link_cfg_from_standards(std1, std0);
> > +		if (link_cfg) {
> > +			/* Swap the 2 standards */
> > +			swap(tp_data->standards[0], tp_data->standards[1]);
> > +
> > +			for (u8 i = 0; i < tp_data->nb_links; ++i)
> > +				tp_data->links[i].std_idx ^= 1;
> > +		}
> > +	}
> 
> [Severity: Medium]
> Does gating the (std1, std0) fallback lookup on !tp_data->clk1 break dual
> reference clock setups where the first DT subnode uses the protocol routed
> to PLL1?
> 
> tp_add_phy_from_of_subnode() populates standards[0] and standards[1] in DT
> subnode order (typically ascending lane address, such as phy@0 then phy@2),
> whereas in tp_link_cfgs[] std0 is always clocked by PLL0 (refclk) and std1
> by PLL1 (pll1_refclk), and most protocol pairs only exist in one PLL
> assignment order (for example, PCIe must be std0 on PLL0).  If phy@0 is
> USXGMII (clocked by pll1_refclk on PLL1) and phy@2 is PCIe (clocked by
> refclk on PLL0), tp_find_link_cfg_from_standards(std0, std1) returns NULL
> and !tp_data->clk1 prevents swapping them to match their required PLL0 and
> PLL1 assignment, failing probe with -EINVAL.

The analysis is correct: this is currently not supported. If a user really
wants to do that, they have to declare the sub-nodes in the "right" order:
PCIe first, then USXGMII, even if the USXGMII reg is 0 (the first lane is
lane 0).
To support this use case, the only solution would be to add a new DTS
property to indicate which PLL to use.

The "old" driver behavior is even more broken in this regard, so the new
code should not introduce any issue.

> [ ... ]
> 
> > +	tp_data->already_configured = tp_is_already_configured(tp_data);
> > +	if (!tp_data->already_configured) {
> > +		ret = tp_ref_clks_init(tp_data);
> > +		if (ret)
> > +			goto cleanup;
> > +	} else {
> > +		tp_init_already_configured_links_opts(tp_data);
> > +	}
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, EXTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, INTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> > +	ret = tp_read_techno_revision(tp_data);
> > +	if (ret)
> > +		goto cleanup;
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_DP, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> > +	tp_check_multiple_pcie_links(tp_data);
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_XAUI, TYPE_PCIE, NO_SSC), &ti_xaui_100_no_ssc_tx_ln_vals},
> > +	ret = tp_find_link_cfg(tp_data);
> > +	if (ret)
> > +		goto cleanup;
> >  
> > -	{CDNS_TORRENT_KEY(CLK_156_25_MHZ, CLK_156_25_MHZ, TYPE_USXGMII, TYPE_NONE, NO_SSC), &usxgmii_156_25_no_ssc_tx_ln_vals},
> > +	ret = tp_dp_reg_base_init(pdev, tp_data);
> > +	if (ret)
> > +		goto cleanup;
> 
> [Severity: High]
> Does tp_init_already_configured_links_opts() dereference a NULL
> tp_data->base when a DisplayPort link is present?
> 
> For DisplayPort links, tp_init_already_configured_links_opts() calls
> tp_dp_find_used_lanes() -> tp_reg_dptx_read(tp_data, PHY_RESET), which
> reads from tp_data->base before tp_dp_reg_base_init() maps the DPTX
> registers.

This is indeed a bug, which was already mentioned:

> In addition, when tp_data->already_configured is true at
> probe time, tp_dp_find_used_lanes() dereferences tp_data->base while it is
> still NULL and tp_dp_update_pll_freq() divides by zero because
> ref_clk_khz is never initialized.

To fix it tp_dp_reg_base_init() will be called earlier in the probe.

-- 
Benjamin Robin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com




WARNING: multiple messages have this Message-ID (diff)
From: Benjamin Robin <benjamin.robin@bootlin.com>
To: sashiko-reviews@lists.linux.dev
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-phy@lists.infradead.org, robh@kernel.org,
	conor+dt@kernel.org, vkoul@kernel.org, neil.armstrong@linaro.org,
	olteanv@gmail.com
Subject: Re: [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver
Date: Wed, 02 Dec 2026 18:18:20 +0100	[thread overview]
Message-ID: <lbqIPw3eTcKROZQUbD6PdA@bootlin.com> (raw)
In-Reply-To: <sashiko-outbox-246119@kernel.org>

On Wednesday, December 2, 2026 at 4:38 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 8 potential
> issues to consider:
> - [High] phy: cadence-torrent: broken QSGMII mode check in
>   tp_add_phy_from_of_subnode()
> - [High] phy: cadence-torrent: divide-by-zero in tp_dp_update_pll_freq()
> - [High] phy: cadence-torrent: NULL dereference of base in
>   tp_dp_find_used_lanes()
> - [High] phy: cadence-torrent: A3 timeout on unused DP lanes and partial
>   lane config
> - [High] phy: cadence-torrent: NULL deref, div-by-zero, and reset bug if
>   preconfigured
> - [Medium] phy: cadence-torrent: wrong std1 initialization in
>   tp_calc_pll_fb_div_modes()
> - [Medium] phy: cadence-torrent: broken dual-refclk validation in
>   tp_ref_clk_init()
> - [Medium] phy: cadence-torrent: rejected standard swap with clk1 in
>   tp_find_link_cfg()
> --
> 
> commit 107a7c6a980951f00c775c6427a095f0f4912099
> Author: Benjamin Robin <benjamin.robin@bootlin.com>
> 
> phy: cadence-torrent: rewrite Torrent PHY driver
> 
> This commit rewrites the Cadence Torrent PHY driver to compute reference
> clock and PLL register values at run time and select protocol, revision,
> and process-node settings from compact configuration tables instead of
> hard-coded register arrays.
> 
> > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> > index 7c4c20b005a95..21ad6c30a3f20 100644
> > --- a/drivers/phy/cadence/phy-cadence-torrent.c
> > +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> 
> [ ... ]
> 
> > +static void tp_calc_pll_fb_div_modes(struct tp_data *tp_data)
> > +		if ((std0->flags & STD_FLAG_PCIE_ML) || std1->type == STD_TYPE_NONE)
> > +			tp_data->plls[PLL1_MODE0].fb_div_mode = div_mode;
> > +		else
> > +			tp_data->plls[PLL1_MODE0].fb_div_mode = PLL_FB_DIV_MODE_FBR;
> 
> [Severity: Medium]
> Should std1 be initialized to &tp_data->standards[1] instead of
> &tp_data->standards[0]?
> 
> Because std1 points to standards[0], std1->type == STD_TYPE_NONE is always
> false inside the std0->type == STD_TYPE_PCIE branch, so single-link PCIe
> configurations set plls[PLL1_MODE0].fb_div_mode to PLL_FB_DIV_MODE_FBR
> instead of div_mode.

This is indeed a bug, and will be fixed in v3.

> [ ... ]
> 
> > +static int tp_dp_update_pll_freq(struct tp_data *tp_data, const struct tp_link *link,
> > +				 enum tp_pll_id pll_id, u32 bit_rate, bool ssc)
> >  {
> > -	struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> > -
> > -	tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0);
> > -	tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1);
> > -	tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 0);
> > +	const struct tp_link_cfg *link_cfg = tp_data->link_cfg;
> > +	struct tp_pll_data *pll = &tp_data->plls[pll_id];
> > +	u32 pll_freq_khz = 0;
> > +	u16 val;
> >  
> > -	return 0;
> > -}
> > +	if (link_cfg->pll_freq[pll_id] != PLL_DP)
> > +		return -EINVAL;
> >  
> > -static void tp_refclk_driver_disable(struct clk_hw *hw)
> > -{
> > -	struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> > +	pll_freq_khz = tp_dp_pll_freq_from_bit_rate(bit_rate);
> > +	if (pll_freq_khz == 0)
> > +		return -EINVAL;
> >  
> > -	tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1);
> > -}
> > +	pll->freq_khz = pll_freq_khz;
> > +	pll->ssc = ssc;
> > +	pll->fractional_mode = tp_is_pll_fractional_mode_required(pll);
> >  
> > -static int tp_refclk_driver_is_enabled(struct clk_hw *hw)
> > -{
> > -	struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> > -	u16 val;
> > +	val = tp_dp_pll_clk_sel_from_bit_rate(bit_rate);
> > +	tp_reg_write(&tp_data->reg_common_cdb, CMN_PDIAG_PLLx_CLK_SEL_Mx(pll_id), val);
> >  
> > -	val = tp_reg_field_read(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1]);
> > -	return !val;
> > -}
> > +	val = tp_dp_xcvr_diag_hsclk_div_from_bit_rate(bit_rate);
> > +	tp_write_lanes_reg(tp_data->reg_tx_lane_cdb, link->mlane, link->max_lanes,
> > +			   XCVR_DIAG_HSCLK_DIV, val);
> >  
> > -static u8 tp_refclk_driver_get_parent(struct clk_hw *hw)
> > -{
> > -	struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> > -	u16 val;
> > +	tp_write_pll_lock_tmr(tp_data, pll_id);
> > +	tp_write_pll_regs(tp_data, pll_id);
> 
> [Severity: High]
> Can tp_dp_update_pll_freq() divide by zero when tp_data->already_configured
> was true at probe time?
> 
> When tp_data->already_configured is true, cdns_torrent_phy_probe() skips
> both tp_ref_clks_init() and tp_configure_links() (and tp_resume_noirq()
> also skips tp_configure_links() -> tp_init_plls_data() if nb_phy_on > 0 and
> the PHY remained configured), leaving tp_data->ref_clk_khz and
> pll->ref_clk_khz at 0.  Calling phy_configure() with opts->dp.set_rate set
> then reaches tp_dp_update_pll_freq(), where
> tp_is_pll_fractional_mode_required() and tp_write_pll_regs() divide by
> pll->ref_clk_khz.

This is indeed a bug. Previously the configuration was completely disabled.
In the v3 the rate configuration will only be allowed if the reference clock
was initialized.
 
> [ ... ]
> 
> > +/* Configure link rate as required. */
> > +static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link,
> > +			  const struct phy_configure_opts_dp *dp)
> > +{
> > +	int ret;
> >  
> > -static const struct cdns_torrent_vals usb_sgmii_xcvr_diag_ln_vals = {
> > -	.reg_pairs = usb_sgmii_xcvr_diag_ln_regs,
> > -	.num_regs = ARRAY_SIZE(usb_sgmii_xcvr_diag_ln_regs),
> > -};
> > +	ret = tp_dptx_set_power_state(tp_data, link->mlane, link->max_lanes, POWERSTATE_A3);
> > +	if (ret)
> > +		return ret;
> 
> [Severity: High]
> Does tp_dptx_set_power_state() time out here when reconfiguring the link
> rate while link->num_lanes < link->max_lanes?
> 
> When fewer than link->max_lanes lanes are active (for example 1 or 2 lanes
> on a 4-lane DP link) and phy_configure() updates the link rate without
> changing the lane count, the active lanes are in POWERSTATE_A0 while unused
> lanes are held in reset with PHY_PMA_XCVR_PLLCLK_EN cleared.  Passing
> link->max_lanes to tp_dptx_set_power_state() causes (read_val & mask) to be
> non-zero, and readl_poll_timeout() then waits for the reset lanes to
> acknowledge POWERSTATE_A3 in PHY_PMA_XCVR_POWER_STATE_ACK and fails with
> -ETIMEDOUT.
> 
> In addition, tp_configure_links() programs per-lane CDB registers only up
> to link->num_lanes instead of link->max_lanes, which leaves upper lanes
> unconfigured after a suspend/resume cycle if the lane count is later
> increased.

This might be an issue. In v3 for the lanes in reset, do not try to go to
POWERSTATE_A3 (ask 0), so it should fix the issue.
 
> [ ... ]
> 
> > +static int tp_phy_on(struct phy *phy)
> > +{
> > +	struct tp_link *link = phy_get_drvdata(phy);
> > +	struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
> > +	u16 val;
> > +	int ret;
> >  
> > -static const struct cdns_torrent_vals pcie_sgmii_xcvr_diag_ln_vals = {
> > -	.reg_pairs = pcie_sgmii_xcvr_diag_ln_regs,
> > -	.num_regs = ARRAY_SIZE(pcie_sgmii_xcvr_diag_ln_regs),
> > -};
> > +	guard(mutex)(&tp_data->lock);
> >  
> > -static const struct cdns_torrent_vals sgmii_pcie_xcvr_diag_ln_vals = {
> > -	.reg_pairs = sgmii_pcie_xcvr_diag_ln_regs,
> > -	.num_regs = ARRAY_SIZE(sgmii_pcie_xcvr_diag_ln_regs),
> > -};
> > +	if (tp_data->already_configured) {
> > +		/* Give 5ms to 10ms delay for the PIPE clock to be stable */
> > +		usleep_range(5000, 10000);
> > +		tp_data->nb_phy_on++;
> > +		return 0;
> > +	}
> 
> [ ... ]
> 
> > +static int tp_phy_off(struct phy *phy)
> > +{
> > +	struct tp_link *link = phy_get_drvdata(phy);
> > +	struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
> > +	int ret;
> >  
> > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_cmn_vals = {
> > -	.reg_pairs = qsgmii_100_no_ssc_cmn_regs,
> > -	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_cmn_regs),
> > -};
> > +	guard(mutex)(&tp_data->lock);
> >  
> > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_tx_ln_vals = {
> > -	.reg_pairs = qsgmii_100_no_ssc_tx_ln_regs,
> > -	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_tx_ln_regs),
> > -};
> > +	ret = tp_control_link_reset(link, true);
> > +	if (ret)
> > +		return ret;
> >  
> > -static const struct cdns_torrent_vals ti_qsgmii_100_no_ssc_tx_ln_vals = {
> > -	.reg_pairs = ti_qsgmii_100_no_ssc_tx_ln_regs,
> > -	.num_regs = ARRAY_SIZE(ti_qsgmii_100_no_ssc_tx_ln_regs),
> > -};
> > +	if (tp_data->nb_phy_on == 1) {
> > +		ret = reset_control_assert(tp_data->phy_rst);
> > +		if (ret)
> > +			return ret;
> > +	}
> >  
> > -static const struct cdns_torrent_vals qsgmii_100_no_ssc_rx_ln_vals = {
> > -	.reg_pairs = qsgmii_100_no_ssc_rx_ln_regs,
> > -	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_rx_ln_regs),
> > -};
> > +	tp_data->nb_phy_on--;
> > +	return 0;
> > +}
> 
> [Severity: High]
> What happens if a pre-configured PHY (tp_data->already_configured == true)
> is powered off and then powered back on?
> 
> tp_phy_off() asserts link->lnk_rst and tp_data->phy_rst without clearing
> tp_data->already_configured, so a subsequent tp_phy_on() takes the early
> already_configured return and leaves both resets asserted and the PHY
> unconfigured.  In addition, when tp_data->already_configured is true at
> probe time, tp_dp_find_used_lanes() dereferences tp_data->base while it is
> still NULL and tp_dp_update_pll_freq() divides by zero because
> ref_clk_khz is never initialized.

This might be an issue. In v3 if already_configured then the resets will be
controlled normally from tp_phy_on().

The NULL dereference is indeed a bug. To fix it tp_dp_reg_base_init() will
be called earlier in the probe.

> [ ... ]
> 
> > +static int tp_ref_clk_init(const struct tp_data *tp_data, struct clk *clk, const char *name,
> > +			   u32 *p_ref_clk_khz)
> > +{
> > +	struct device *dev = tp_data->dev;
> > +	u32 ref_clk_rate;
> > +	int ret;
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_SGMII, NO_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> > +	ret = clk_prepare_enable(clk);
> > +	if (ret) {
> > +		dev_err(dev, "Failed to prepare %s ref clock: %d\n", name, ret);
> > +		return ret;
> > +	}
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, NO_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, EXTERNAL_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, INTERNAL_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> > +	ref_clk_rate = clk_get_rate(clk);
> > +	if (!ref_clk_rate) {
> > +		dev_err(dev, "Failed to get %s ref clock rate\n", name);
> > +		ret = -EINVAL;
> > +		goto disable_clk;
> > +	}
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, NO_SSC), &usb_100_no_ssc_rx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, EXTERNAL_SSC), &usb_100_no_ssc_rx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, INTERNAL_SSC), &usb_100_no_ssc_rx_ln_vals},
> > +	for (u8 i = 0; i < tp_data->nb_links; ++i) {
> > +		if (!tp_is_ref_freq_supported(tp_data->links[i].type, ref_clk_rate)) {
> > +			dev_err(dev, "Invalid ref clock rate: %u Hz\n", ref_clk_rate);
> > +			ret = -EINVAL;
> > +			goto disable_clk;
> > +		}
> > +	}
> 
> [Severity: Medium]
> Does validating ref_clk_rate against all links in tp_data->links[] reject
> valid dual-reference-clock configurations?
> 
> When both refclk (PLL0) and pll1_refclk (PLL1) are provided,
> tp_ref_clks_init() calls tp_ref_clk_init() for each clock, and this loop
> requires both frequencies to be supported by every link's standard.  A
> setup such as SATA at 100 MHz on PLL0 with USXGMII at 156.25 MHz on PLL1
> fails probe with -EINVAL because 156.25 MHz is not in SATA's supported
> frequency list (freq_set4).

I largely agree with this remark, but this is the current behavior of the
Cadence "Torrent Programmers Guide" spreadsheet. So for now, keep the same
behavior as documented by Cadence, but that seems a bit strange.

> [ ... ]
> 
> > +	switch (phy_type) {
> > +	case PHY_TYPE_PCIE:
> > +		std_type = STD_TYPE_PCIE;
> > +		break;
> > +	case PHY_TYPE_USB3:
> > +		std_type = STD_TYPE_USB_TXRX;
> > +		supported_flags = CDNS_TORRENT_MODE_USB_G1 | CDNS_TORRENT_MODE_USB_IO_11V;
> > +		break;
> > +	case PHY_TYPE_DP:
> > +		std_type = STD_TYPE_DP;
> > +		break;
> > +	case PHY_TYPE_XAUI:
> > +		std_type = STD_TYPE_XAUI;
> > +		supported_flags = CDNS_TORRENT_MODE_XAUI_LP;
> > +		break;
> > +	case PHY_TYPE_SGMII:
> > +		std_type = STD_TYPE_SGMII;
> > +		supported_flags = CDNS_TORRENT_MODE_2500_BASEX;
> > +		break;
> > +	case PHY_TYPE_QSGMII:
> > +		std_type = STD_TYPE_SGMII;
> > +		link_flags |= STD_FLAG_QSGMII;
> > +		break;
> > +	case PHY_TYPE_SATA:
> > +		std_type = STD_TYPE_SATA;
> > +		supported_flags = CDNS_TORRENT_MODE_SATA_LP;
> > +		break;
> > +	case PHY_TYPE_USXGMII:
> > +		std_type = STD_TYPE_USXGMII;
> > +		break;
> > +	default:
> > +		dev_err(dev, "Unsupported protocol: %u\n", phy_type);
> > +		return -EINVAL;
> > +	}
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, EXTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, INTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> > +	if (link_flags & ~supported_flags) {
> > +		dev_err(dev, "Unsupported modes 0x%X for this PHY type %u\n",
> > +			link_flags, std_type);
> > +		return -EINVAL;
> > +	}
> 
> [Severity: High]
> Does PHY_TYPE_QSGMII always fail this check with -EINVAL?
> 
> The PHY_TYPE_QSGMII case sets STD_FLAG_QSGMII in link_flags while leaving
> supported_flags at 0, so (link_flags & ~supported_flags) is always
> non-zero.

This is indeed a bug introduced while refactoring and removing the QSGMII flag
from dt-bindings. This will be fixed in v3.
 
> [ ... ]
> 
> > +	link_cfg = tp_find_link_cfg_from_standards(std0, std1);
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, NO_SSC), &usb_100_no_ssc_cmn_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, EXTERNAL_SSC), &usb_100_no_ssc_cmn_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, INTERNAL_SSC), &usb_100_no_ssc_cmn_vals},
> > +	/* Only swap the two standards if PLL1 has no dedicated reference clock. If
> > +	 * there are two DTS PHY nodes and the `pll1_refclk` reference clock is
> > +	 * specified, the user assumes the PLL1 reference clock will be used for the
> > +	 * second DTS PHY node. If the standards are swapped, this clock would be used
> > +	 * for the first DTS PHY node instead, which could be a problem, for example
> > +	 * with USXGMII, which prefers a 156.25 MHz reference clock.
> > +	 */
> > +	if (!link_cfg && !tp_data->clk1) {
> > +		link_cfg = tp_find_link_cfg_from_standards(std1, std0);
> > +		if (link_cfg) {
> > +			/* Swap the 2 standards */
> > +			swap(tp_data->standards[0], tp_data->standards[1]);
> > +
> > +			for (u8 i = 0; i < tp_data->nb_links; ++i)
> > +				tp_data->links[i].std_idx ^= 1;
> > +		}
> > +	}
> 
> [Severity: Medium]
> Does gating the (std1, std0) fallback lookup on !tp_data->clk1 break dual
> reference clock setups where the first DT subnode uses the protocol routed
> to PLL1?
> 
> tp_add_phy_from_of_subnode() populates standards[0] and standards[1] in DT
> subnode order (typically ascending lane address, such as phy@0 then phy@2),
> whereas in tp_link_cfgs[] std0 is always clocked by PLL0 (refclk) and std1
> by PLL1 (pll1_refclk), and most protocol pairs only exist in one PLL
> assignment order (for example, PCIe must be std0 on PLL0).  If phy@0 is
> USXGMII (clocked by pll1_refclk on PLL1) and phy@2 is PCIe (clocked by
> refclk on PLL0), tp_find_link_cfg_from_standards(std0, std1) returns NULL
> and !tp_data->clk1 prevents swapping them to match their required PLL0 and
> PLL1 assignment, failing probe with -EINVAL.

The analysis is correct: this is currently not supported. If a user really
wants to do that, they have to declare the sub-nodes in the "right" order:
PCIe first, then USXGMII, even if the USXGMII reg is 0 (the first lane is
lane 0).
To support this use case, the only solution would be to add a new DTS
property to indicate which PLL to use.

The "old" driver behavior is even more broken in this regard, so the new
code should not introduce any issue.

> [ ... ]
> 
> > +	tp_data->already_configured = tp_is_already_configured(tp_data);
> > +	if (!tp_data->already_configured) {
> > +		ret = tp_ref_clks_init(tp_data);
> > +		if (ret)
> > +			goto cleanup;
> > +	} else {
> > +		tp_init_already_configured_links_opts(tp_data);
> > +	}
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, EXTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, INTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> > +	ret = tp_read_techno_revision(tp_data);
> > +	if (ret)
> > +		goto cleanup;
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_DP, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> > +	tp_check_multiple_pcie_links(tp_data);
> >  
> > -	{CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_XAUI, TYPE_PCIE, NO_SSC), &ti_xaui_100_no_ssc_tx_ln_vals},
> > +	ret = tp_find_link_cfg(tp_data);
> > +	if (ret)
> > +		goto cleanup;
> >  
> > -	{CDNS_TORRENT_KEY(CLK_156_25_MHZ, CLK_156_25_MHZ, TYPE_USXGMII, TYPE_NONE, NO_SSC), &usxgmii_156_25_no_ssc_tx_ln_vals},
> > +	ret = tp_dp_reg_base_init(pdev, tp_data);
> > +	if (ret)
> > +		goto cleanup;
> 
> [Severity: High]
> Does tp_init_already_configured_links_opts() dereference a NULL
> tp_data->base when a DisplayPort link is present?
> 
> For DisplayPort links, tp_init_already_configured_links_opts() calls
> tp_dp_find_used_lanes() -> tp_reg_dptx_read(tp_data, PHY_RESET), which
> reads from tp_data->base before tp_dp_reg_base_init() maps the DPTX
> registers.

This is indeed a bug, which was already mentioned:

> In addition, when tp_data->already_configured is true at
> probe time, tp_dp_find_used_lanes() dereferences tp_data->base while it is
> still NULL and tp_dp_update_pll_freq() divides by zero because
> ref_clk_khz is never initialized.

To fix it tp_dp_reg_base_init() will be called earlier in the probe.

-- 
Benjamin Robin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com




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

  reply	other threads:[~2026-12-02 17:18 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:24   ` sashiko-bot
2026-12-02 15:24     ` sashiko-bot
2026-12-02 15:08 ` [PATCH v2 02/22] drm/bridge: cdns-mhdp8546: Power on/off the PHY in probe/remove Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 03/22] dt-bindings: phy: cadence-torrent: make cdns,num-lanes optional again Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 05/22] phy: cadence-torrent: make cdns,num-lanes optional again Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 06/22] phy: torrent: fix `RX_DIAG_NQST_CTRL` register address Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 07/22] phy: cadence-torrent: rename symbols to prepare for rewrite Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 08/22] phy: cadence-torrent: replace regmap with readw/writew Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 09/22] phy: cadence-torrent: move refclk clk_init_data to the stack Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 10/22] phy: cadence-torrent: drop diag_tx_drv from DP voltage coeff Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:28   ` sashiko-bot
2026-12-02 15:28     ` sashiko-bot
2026-12-02 15:08 ` [PATCH v2 12/22] phy: cadence-torrent: use devm_of_clk_add_hw_provider() Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 13/22] phy: cadence-torrent: rework subnode parsing and lane validation Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:24   ` sashiko-bot
2026-12-02 15:24     ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 15/22] phy: cadence-torrent: factor out DP PLL frequency update Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 16/22] phy: cadence-torrent: store clock and reset handles only on success Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:37   ` sashiko-bot
2026-12-02 15:37     ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:31   ` sashiko-bot
2026-12-02 15:31     ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 19/22] phy: cadence-torrent: track current DP link bit rate Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 20/22] phy: cadence-torrent: rework suspend/resume to restore link config Benjamin Robin
2026-12-02 15:34   ` sashiko-bot
2026-12-02 15:34     ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
2026-12-02 15:38   ` sashiko-bot
2026-12-02 15:38     ` sashiko-bot
2026-12-02 17:18     ` Benjamin Robin [this message]
2026-12-02 17:18       ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:30   ` sashiko-bot
2026-12-02 15:30     ` 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=lbqIPw3eTcKROZQUbD6PdA@bootlin.com \
    --to=benjamin.robin@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.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.