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 <[email protected]> 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/[email protected]?part=18
