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 <[email protected]> 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. 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. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=14
