From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.84.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796313386; b=pn1UUkB7vn6FyfG9X18KhPIF+i2DJVn857zNuEGEPM/owS1oWgjlc3FC1PMPHw2gF/Z8 Xy0Fp+EAzeEWUOGWhOlrgSqWi/R+FN3eNiZJLc9OT+aEk0lgJYC2iG8QsLNhdKAduGOhF tbtsrXkyIoQauWZNSEUDrDYVReMEHoUywg0+CvVLoJjYG18Af25Y+XUFGyKsA3lwpvMfy Z7FL5Wb63O4PhzScZEPfRYt/a5wGAcpo+PbGTXKTgtQNG9NXkgCXpqQS88t+w4etCynYY 2uJ+FqiuWyWZczrSLzZa/lLDOKoSgqi79wq5fY4bqqeV/HuxsILYzS1b5RCSgIN6etw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313386; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Last-TLS-Session-Version; bh=pPw6g/8h6arc5BoN3cJw8v+KXcb5/poNv1IGGwNvLNM=; b=whNpwk6xktVSCHMYt0CdzIU02oAOrdlLaA3clW0X5uUQTjuM7MgtfjincvMIf4zZ+BYJ o4RsGxXMdaQ1JKDhQjgyEfBatd1g2q7eUBaXg2oQZWW1CNmnVM/oD//ydi9hEBx6PDtgy tCY4lzwEH+6v8mJQULojKldCbw5KGgmbP6niH/F0MmPQQT7zR7GIL0BjLY664OdV3MbFc M44nLX8R0D4yRJOfqN3PY72ph4yA25C/yDlFQyhXJ10yxTtLuPArLK77ea1ha7CIslu99 6eVBZyVv2RD8T5lMQLHO+YWWdFC5D5OTEsgjCe6LhumrlQJmS6wBa7gKGsKAYVMuYYg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b="tfLui/El"; arc=none smtp.remote-ip=185.246.84.56 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C1F8606A32C for ; Thu, 3 Dec 2026 15:56:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4C1F8606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=tfLui/El Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 8AFDF1A191C; Thu, 3 Dec 2026 15:56:23 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 47164604C0; Thu, 3 Dec 2026 15:56:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D699111EA1873; Thu, 03 Dec 2026 16:56:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796313378; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=pPw6g/8h6arc5BoN3cJw8v+KXcb5/poNv1IGGwNvLNM=; b=tfLui/Ell+LgHnJSsYzMfSkXI0yn2MQkdPq82PeCiCkydVvIa3H2fM2ptN7kvmkGMHg6o0 mvJH7M2rEAvtmDdoW1ZkLK2ux7XcUjI9vc5ZRBUArV1xBTbNaj3YYrOSjWq2OTX9WpTala Daii/oc0TSQunJXVzTWxJPndbgMWh586nkOP0gsZFF2Dq28o1Iv5Gzit8zkgXiW8T0HxsR H2ZWdtRwIJ5+sG4oUg9xQTgfoWTsWlRik+QVslIxV7MRK3G8TmeYDBtE3gHDEU7aXNB8mt XTypfrKXv1RcyyUDtxDoDU6IlxNyYlCeTXDcjLWK4QBDsxM4FTZEX89gbZ45/w== From: Benjamin Robin 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 18/22] phy: cadence-torrent: allow config on an already-configured DP link Date: Thu, 03 Dec 2026 16:56:15 +0100 Message-ID: In-Reply-To: References: <20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com> <20261202-phy-cadence-torrent-ng-v2-18-0b493387347b@bootlin.com> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Last-TLS-Session-Version: TLSv1.3 On Wednesday, December 2, 2026 at 4:31=E2=80=AFPM, sashiko-bot@kernel.org w= rote: > 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() > -- >=20 > commit 26b8eac666ec602cc77dee851e18adb2e17e76e7 > Author: Benjamin Robin >=20 > phy: cadence-torrent: allow config on an already-configured DP link >=20 > 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. >=20 > > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/ca= dence/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_l= ink *link, > > return 0; > > } > > =20 > > +static void tp_dp_find_used_lanes(const struct tp_data *tp_data, struc= t tp_link *link) > > +{ > > + u32 mlane =3D link->mlane; > > + u32 used_lanes_mask; > > + u32 all_lane_mask; > > + u32 value; > > + > > + all_lane_mask =3D ((1U << link->max_lanes) - 1) << mlane; > > + value =3D tp_reg_dptx_read(tp_data, PHY_RESET); > > + > > + /* only keep the lanes not in reset */ > > + used_lanes_mask =3D value & all_lane_mask; > > + > > + /* only keep the lanes with Tx differential output not into electrica= l idle */ > > + used_lanes_mask &=3D (~(value >> PMA_TX_ELEC_IDLE_SHIFT)) & all_lane_= mask; > > + > > + /* update the number of used lanes */ > > + used_lanes_mask >>=3D mlane; > > + link->num_lanes =3D __ffs(~used_lanes_mask); > > +} >=20 > [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? Yes it could, and this should not be an issue, except for the bug described below. > In a multi-link setup where the bootloader only configured the non-DP lin= k, > 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 =3D=3D 0 and __ffs(~used_lanes_mask) =3D=3D 0. If the sy= stem > 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 lin= k. In v3 it will not skip programming the per-lane PMA TX/RX CDB registers for the DP link since max_lanes will be used instead of num_lanes. So this part of the issue will be fixed. =20 > > @@ -1433,9 +1454,6 @@ static int tp_phy_configure(struct phy *phy, unio= n phy_configure_opts *opts) > > =20 > > guard(mutex)(&tp_data->lock); > > =20 > > - if (tp_data->already_configured) > > - return 0; > > - > > if (link->phy_type !=3D TYPE_DP) > > return -EINVAL; >=20 > [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? In v3 set_rate will be disabled if ref_clks_initialized is false because already_configured was true. This is technically impossible to configure the DP rate if the reference clock frequency is unknown. In practice U-boot does not configure the torrent PHY for DisplayPort link so already_configured is false in this case. =20 > 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: >=20 > drivers/phy/cadence/phy-cadence-torrent.c:tp_dp_configure_rate() { > ... > pll_mask =3D tp_data->dp_pll; > ... > tp_reg_clear_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask); > ... > ret =3D read_poll_timeout(tp_reg_read, val, (val & (pll_mask << 2)) !=3D= 0, 0, > POLL_TIMEOUT_US, false, reg_base, PHY_PMA_CMN_CTRL2); > ... > } >=20 > Because (val & (pll_mask << 2)) !=3D 0 is always false, tp_dp_configure_r= ate() > 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(). >=20 > [ ... ] >=20 > > @@ -2750,6 +2778,8 @@ static int cdns_torrent_phy_probe(struct platform= _device *pdev) > > ret =3D tp_ref_clks_init(tp_data); > > if (ret) > > goto cleanup; > > + } else { > > + tp_init_already_configured_links_opts(tp_data); > > } > > =20 > > ret =3D tp_dp_reg_base_init(pdev, tp_data); >=20 > [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? >=20 > 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. Yes it does... It will be fixed in v3 =2D-=20 Benjamin Robin, Bootlin Embedded Linux and Kernel engineering https://bootlin.com