Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Benjamin Robin" <benjamin.robin@bootlin.com>
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 18/22] phy: cadence-torrent: allow config on an already-configured DP link
Date: Wed, 02 Dec 2026 15:31:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-246108@kernel.org> (raw)
In-Reply-To: <20261202-phy-cadence-torrent-ng-v2-18-0b493387347b@bootlin.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] phy: cadence-torrent: NULL pointer dereference in
  tp_dp_find_used_lanes()
- [High] phy: cadence-torrent: uninitialized dp_pll and ref_clk in
  tp_phy_configure()
- [Medium] phy: cadence-torrent: link->num_lanes set to 0 in
  tp_dp_find_used_lanes()
--

commit 26b8eac666ec602cc77dee851e18adb2e17e76e7
Author: Benjamin Robin <benjamin.robin@bootlin.com>

phy: cadence-torrent: allow config on an already-configured DP link

This commit removes the early return for already-configured PHYs in
tp_phy_configure() and reads the active DisplayPort lane count from the
PHY_RESET register during probe when the PHY is already configured.

> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> index 3b4d52ee7a531..0cbbedeefd87a 100644
> --- a/drivers/phy/cadence/phy-cadence-torrent.c
> +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> @@ -1310,6 +1310,27 @@ static int tp_dp_verify_config(const struct tp_link *link,
>  	return 0;
>  }
>  
> +static void tp_dp_find_used_lanes(const struct tp_data *tp_data, struct tp_link *link)
> +{
> +	u32 mlane = link->mlane;
> +	u32 used_lanes_mask;
> +	u32 all_lane_mask;
> +	u32 value;
> +
> +	all_lane_mask = ((1U << link->max_lanes) - 1) << mlane;
> +	value = tp_reg_dptx_read(tp_data, PHY_RESET);
> +
> +	/* only keep the lanes not in reset */
> +	used_lanes_mask = value & all_lane_mask;
> +
> +	/* only keep the lanes with Tx differential output not into electrical idle */
> +	used_lanes_mask &= (~(value >> PMA_TX_ELEC_IDLE_SHIFT)) & all_lane_mask;
> +
> +	/* update the number of used lanes */
> +	used_lanes_mask >>= mlane;
> +	link->num_lanes = __ffs(~used_lanes_mask);
> +}

[Severity: Medium]
Can tp_dp_find_used_lanes() overwrite link->num_lanes with 0 when all
DisplayPort lanes are held in reset or electrical idle at probe time?

In a multi-link setup where the bootloader only configured the non-DP link,
tp_is_already_configured() still returns true because the shared
PHY_PMA_CMN_CTRL1 bit 0 is set, while the DP lanes in PHY_RESET have
used_lanes_mask == 0 and __ffs(~used_lanes_mask) == 0.  If the system
suspends and resumes before DP link training updates link->num_lanes,
tp_resume_noirq() -> tp_configure_links() loops over 0 .. link->num_lanes - 1
and skips programming the per-lane PMA TX/RX CDB registers for the DP link.

> @@ -1433,9 +1454,6 @@ static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
>  
>  	guard(mutex)(&tp_data->lock);
>  
> -	if (tp_data->already_configured)
> -		return 0;
> -
>  	if (link->phy_type != TYPE_DP)
>  		return -EINVAL;

[Severity: High]
Will tp_phy_configure() fail with -ETIMEDOUT when opts->dp.set_rate is set
on an already-configured PHY because tp_data->dp_pll and
tp_data->ref_clk_rate were never initialized?

When tp_data->already_configured is true, cdns_torrent_phy_probe() skips
both tp_ref_clks_init() and tp_configure_links() (which calls
cdns_torrent_dp_get_pll()), leaving tp_data->dp_pll and
tp_data->ref_clk_rate at 0.  When tp_phy_configure() calls
tp_dp_set_rate() -> tp_dp_configure_rate(), pll_mask is 0 after the lanes
have already been put into POWERSTATE_A3:

drivers/phy/cadence/phy-cadence-torrent.c:tp_dp_configure_rate() {
	...
	pll_mask = tp_data->dp_pll;
	...
	tp_reg_clear_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask);
	...
	ret = read_poll_timeout(tp_reg_read, val, (val & (pll_mask << 2)) != 0, 0,
				POLL_TIMEOUT_US, false, reg_base, PHY_PMA_CMN_CTRL2);
	...
}

Because (val & (pll_mask << 2)) != 0 is always false, tp_dp_configure_rate()
times out and leaves the DisplayPort lanes powered down.  Later in the
series, commit "phy: cadence-torrent: rewrite Torrent PHY driver" replaces
dp_pll with 1U << link->std_idx, but tp_ref_clks_init() and
tp_init_plls_data() are still skipped when tp_data->already_configured is
true, leaving pll->ref_clk_khz at 0 in tp_write_pll_regs().

[ ... ]

> @@ -2750,6 +2778,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
>  		ret = tp_ref_clks_init(tp_data);
>  		if (ret)
>  			goto cleanup;
> +	} else {
> +		tp_init_already_configured_links_opts(tp_data);
>  	}
>  
>  	ret = tp_dp_reg_base_init(pdev, tp_data);

[Severity: High]
Does calling tp_init_already_configured_links_opts() before
tp_dp_reg_base_init() cause a NULL pointer dereference on tp_data->base?

When tp_data->already_configured is true and a TYPE_DP link is present,
tp_init_already_configured_links_opts() -> tp_dp_find_used_lanes() ->
tp_reg_dptx_read() reads from tp_data->base + PHY_RESET, but tp_data->base
is only ioremapped in tp_dp_reg_base_init() immediately afterwards.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=18

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

  parent reply	other threads:[~2026-12-02 15:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com>
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 ` [PATCH v2 07/22] phy: cadence-torrent: rename symbols to prepare for rewrite 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 ` [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config Benjamin Robin
2026-12-02 15:28   ` sashiko-bot
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:24   ` sashiko-bot
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 ` [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe Benjamin Robin
2026-12-02 15:37   ` sashiko-bot
     [not found] ` <20261202-phy-cadence-torrent-ng-v2-1-0b493387347b@bootlin.com>
2026-12-02 15:24   ` [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY sashiko-bot
     [not found] ` <20261202-phy-cadence-torrent-ng-v2-22-0b493387347b@bootlin.com>
2026-12-02 15:30   ` [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY sashiko-bot
     [not found] ` <20261202-phy-cadence-torrent-ng-v2-18-0b493387347b@bootlin.com>
2026-12-02 15:31   ` sashiko-bot [this message]
     [not found] ` <20261202-phy-cadence-torrent-ng-v2-20-0b493387347b@bootlin.com>
2026-12-02 15:34   ` [PATCH v2 20/22] phy: cadence-torrent: rework suspend/resume to restore link config sashiko-bot
     [not found] ` <20261202-phy-cadence-torrent-ng-v2-21-0b493387347b@bootlin.com>
2026-12-02 15:38   ` [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver 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-246108@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox