Linux-PHY Archive on 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 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup
Date: Thu, 03 Dec 2026 15:27:14 +0100	[thread overview]
Message-ID: <oXlCtJIpSP6W1-0euXAKGg@bootlin.com> (raw)
In-Reply-To: <sashiko-outbox-246089@kernel.org>

On Wednesday, December 2, 2026 at 4:24 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] phy: cadence-torrent: invalid reset_control_assert() calls on
>   probe error
> --
> 
> commit d8ca83553938e7b813b4701d8d1a0be332d25133
> Author: Benjamin Robin <benjamin.robin@bootlin.com>
> 
> phy: cadence-torrent: rework ref clock init and probe cleanup
> 
> This commit refactors reference clock initialization into helper functions
> and consolidates probe error handling and driver removal into a shared
> tp_cleanup_remove() helper.
> 
> > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> > index 69e5323b1d689..de4ff3a133ffa 100644
> > --- a/drivers/phy/cadence/phy-cadence-torrent.c
> > +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> [ ... ]
> > @@ -2672,6 +2671,18 @@ static int tp_dp_reg_base_init(struct platform_device *pdev, struct tp_data *tp_
> >  	return 0;
> >  }
> >  
> > +static void tp_cleanup_remove(struct tp_data *tp_data)
> > +{
> > +	for (u8 i = 0; i < tp_data->nb_links; ++i) {
> > +		reset_control_assert(tp_data->links[i].lnk_rst);
> > +		reset_control_put(tp_data->links[i].lnk_rst);
> > +	}
> > +
> > +	reset_control_assert(tp_data->phy_rst);
> > +	reset_control_assert(tp_data->apb_rst);
> > +	tp_ref_clks_uninit(tp_data);
> > +}
> > +
> >  static bool tp_is_already_configured(const struct tp_data *tp_data)
> >  {
> >  	u16 val = tp_reg_read(&tp_data->reg_phy_pma_common_cdb, PHY_PMA_CMN_CTRL1);
> > @@ -2721,21 +2732,11 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
> >  
> >  	ret = tp_of_get_reset(tp_data);
> >  	if (ret)
> > -		return ret;
> > +		goto cleanup;
> >  
> >  	ret = tp_of_get_clk(tp_data);
> >  	if (ret)
> > -		return ret;
> > -
> > -	tp_data->already_configured = tp_is_already_configured(tp_data);
> > -	if (!tp_data->already_configured) {
> > -		ret = cdns_torrent_clk(tp_data);
> > -		if (ret)
> > -			return ret;
> > -
> > -		/* Enable APB */
> > -		reset_control_deassert(tp_data->apb_rst);
> > -	}
> > +		goto cleanup;
> >  
> >  	for_each_available_child_of_node(dev->of_node, child) {
> >  		/* PHY subnode name must be 'phy'. */
> > @@ -2744,29 +2745,39 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
> >  
> >  		ret = tp_add_phy_from_of_subnode(tp_data, child);
> >  		if (ret)
> > -			goto put_lnk_rst;
> > +			goto cleanup;
> >  	}
> >  	child = NULL;
> >  
> >  	if (tp_data->nb_links == 0) {
> >  		ret = -ENODEV;
> > -		goto put_lnk_rst;
> > +		goto cleanup;
> > +	}
> > +
> > +	/* Enable APB */
> > +	reset_control_deassert(tp_data->apb_rst);
> > +
> > +	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;
> >  	}
> >  
> >  	ret = tp_dp_reg_base_init(pdev, tp_data);
> >  	if (ret)
> > -		goto put_lnk_rst;
> > +		goto cleanup;
> >  
> >  	if (tp_data->nb_links > 1 && !tp_data->already_configured) {
> >  		ret = cdns_torrent_phy_configure_multilink(tp_data);
> >  		if (ret)
> > -			goto put_lnk_rst;
> > +			goto cleanup;
> >  	}
> >  
> >  	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> >  	if (IS_ERR(phy_provider)) {
> >  		ret = PTR_ERR(phy_provider);
> > -		goto put_lnk_rst;
> > +		goto cleanup;
> >  	}
> >  
> >  	if (tp_data->nb_links > 1)
> > @@ -2781,33 +2792,19 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
> >  
> >  	return 0;
> >  
> > -put_lnk_rst:
> > +cleanup:
> >  	if (child)
> >  		of_node_put(child);
> >  
> > -	for (u8 i = 0; i < tp_data->nb_links; i++)
> > -		reset_control_put(tp_data->links[i].lnk_rst);
> > -
> > -	reset_control_assert(tp_data->apb_rst);
> > -	clk_disable_unprepare(tp_data->clk1);
> > -	clk_disable_unprepare(tp_data->clk);
> > +	tp_cleanup_remove(tp_data);
> >  	return ret;
> >  }
> 
> [Severity: Medium]
> Can jumping to cleanup from cdns_torrent_phy_probe() trigger a WARN_ON()
> in reset_control_assert() or reset a SERDES that was already configured by
> the bootloader?
>
> If tp_of_get_reset() fails (for example with -EPROBE_DEFER),
> tp_data->phy_rst or tp_data->apb_rst holds an ERR_PTR, which
> tp_cleanup_remove() passes to reset_control_assert(), hitting
> WARN_ON(IS_ERR(rstc)):
> 
> drivers/phy/cadence/phy-cadence-torrent.c:tp_of_get_reset() {
> 	tp_data->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0);
> 	if (IS_ERR(tp_data->phy_rst)) {
> 		dev_err(dev, "%s: failed to get reset\n",
> 			dev->of_node->full_name);
> 		return PTR_ERR(tp_data->phy_rst);
> 	}
>     ...
> }
> 
> Although commit "phy: cadence-torrent: store clock and reset handles only
> on success" later in this series avoids storing the ERR_PTR, ordering that
> change before this one would avoid breaking bisection.

This indeed could be an issue. In v3 the commit "store clock and reset
handles only on success" will be put before this one.

> In addition, calling tp_cleanup_remove() on probe failure after
> tp_of_get_reset() (such as -EPROBE_DEFER in tp_of_get_clk() or
> tp_add_phy_from_of_subnode(), or any failure when
> tp_data->already_configured is true) unconditionally asserts
> links[i].lnk_rst, phy_rst, and apb_rst.  Previously, probe failure never
> asserted phy_rst or links[i].lnk_rst, and asserting these resets on probe
> deferral resets an already-configured SERDES and clears PHY_PMA_CMN_CTRL1,
> so subsequent probe retries no longer detect already_configured.

I guess there is no reason to put the PHY in resets in case of probe failure.
We should keep the reset in their default state.
However when configuring the torrent PHY, everything should be in reset.
This will be changed in v3.

-- 
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-03 14:27 UTC|newest]

Thread overview: 33+ 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 ` [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY Benjamin Robin
2026-12-02 15:24   ` sashiko-bot
2026-12-03 13:59     ` Benjamin Robin
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 ` [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants 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 ` [PATCH v2 06/22] phy: torrent: fix `RX_DIAG_NQST_CTRL` register address 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 09/22] phy: cadence-torrent: move refclk clk_init_data to the stack 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 ` [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 12/22] phy: cadence-torrent: use devm_of_clk_add_hw_provider() 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 ` [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-03 14:27     ` Benjamin Robin [this message]
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 ` [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
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: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 ` [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:09 ` [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY Benjamin Robin
2026-12-02 15:30   ` 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
2026-12-02 17:18     ` Benjamin Robin

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=oXlCtJIpSP6W1-0euXAKGg@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox