Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A00E13B7759 for ; Tue, 11 Aug 2026 15:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786463118; cv=none; b=VuW8WbgKU7UlSzreItXJNMmI31FgqbNZohlaLwve/cn33Un7RSDoRH4+YFySzvQunSh+wsOU2yA3Tu7GL41HHvpR3sgFDbrFk/fltpOYweeavd1OtuyMjVbWJPyUhzPFfxZE630XaekC4ebjStjoIMhLqe500emYHyBtjXYQOMk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786463118; c=relaxed/simple; bh=VPgeGDdA8QmrtAihuQbdXnoRiqxMYVaaD7wuBUl+Txk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d8wMXC4D/Iv0Bg38YBBNdX/yCmKl1hjgd8IUAupNp/2icx3vJZFMfZvV3PYOS7by3gV1RsWOTD7M06U1vh5Uji2UL0saP+/yhmrXu/4GVnuegQugmBPjKcVugDpnCWGCwnjxulmw+V8PwxNO2XTTZx6o1CgNXDUPLaOsDAVbxjY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=fpU96XVq; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="fpU96XVq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1786463114; bh=VPgeGDdA8QmrtAihuQbdXnoRiqxMYVaaD7wuBUl+Txk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fpU96XVq4KjGAlWVkjSh+lbjrdCugOiWPf/6OWGAi0J4B+KaO7muWkPX2HGuVO4iS jxla3qmP6ttON9IHC33peLnQe5hJlEGNn8tw+40xj7FNDNalthIdR6YXgcfFhJEkYG hlGKUXZ3Ov3FcJhURmKJtH08hD8qxkO6O46h2/izb06wyPM5GAPPMikQxAPyqJLLdb 7s2CyIQsKaY9T8Ok6u6gMFwq1cATuCxKaKq8WLJq6WGvTK5cchOfbzeTVfwje6nKEL ehzgErlmpXSr4nOvBg4XesKqltQsfGTSBHrrKV1IRiSqVqmGtwDLlSg37QLl7H9DlE jgnwz1TDkpetQ== Received: from localhost (unknown [100.64.0.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id C07E317E0667; Tue, 11 Aug 2026 17:45:14 +0200 (CEST) From: Cristian Ciocaltea Date: Tue, 11 Aug 2026 18:44:43 +0300 Subject: [PATCH v6 02/10] phy: rockchip: samsung-hdptx: Prevent divide-by-zero when computing clk rate Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260811-hdptx-clk-fixes-v6-2-75bca0ee5753@collabora.com> References: <20260811-hdptx-clk-fixes-v6-0-75bca0ee5753@collabora.com> In-Reply-To: <20260811-hdptx-clk-fixes-v6-0-75bca0ee5753@collabora.com> To: Vinod Koul , Neil Armstrong , Heiko Stuebner , Algea Cao , Dmitry Baryshkov Cc: kernel@collabora.com, linux-phy@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Sashiko , Diederik de Haas , Dmitry Baryshkov , Andy Yan X-Mailer: b4 0.15.2 Calculating 'sdm' fraction in rk_hdptx_phy_clk_calc_rate_from_pll_cfg() could trigger a divide-by-zero, as it uses div_u64() with a denominator read directly from hardware: the values ropll_hw.sdm_deno, ropll_hw.sdc_deno, ropll_hw.sdc_n, and ropll_hw.sdc_num are populated from PLL registers which, in theory, could be left by the bootloader uninitialized/misconfigured. Provide the necessary sanitization to avoid trusting the hardware state. Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260611-hdptx-clk-fixes-v3-0-67b1b0c00e16@collabora.com?part=1 Fixes: 3481fc04d969 ("phy: rockchip: samsung-hdptx: Compute clk rate from PLL config") Tested-by: Diederik de Haas # NanoPC-T6 LTS Reviewed-by: Dmitry Baryshkov Reviewed-by: Andy Yan Signed-off-by: Cristian Ciocaltea --- drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c index 710603afff86..d67ced2bf7b2 100644 --- a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c +++ b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c @@ -2270,10 +2270,20 @@ static u64 rk_hdptx_phy_clk_calc_rate_from_pll_cfg(struct rk_hdptx_phy *hdptx) fout = PLL_REF_CLK * ropll_hw.pms_mdiv; if (ropll_hw.sdm_en) { + val = 16U * ropll_hw.sdm_deno * + (ropll_hw.sdc_deno * ropll_hw.sdc_n - ropll_hw.sdc_num); + if (!val) { + /* + * The PLL config currently stored in hardware can't be + * translated into a rate. The next .set_rate() should + * program a valid configuration and help with recovery. + */ + dev_dbg(hdptx->dev, "Invalid ROPLL hw state: deno == 0\n"); + return 0; + } + sdm = div_u64(PLL_REF_CLK * ropll_hw.sdc_deno * - ropll_hw.pms_mdiv * ropll_hw.sdm_num, - 16 * ropll_hw.sdm_deno * - (ropll_hw.sdc_deno * ropll_hw.sdc_n - ropll_hw.sdc_num)); + ropll_hw.pms_mdiv * ropll_hw.sdm_num, val); if (ropll_hw.sdm_num_sign) fout = fout - sdm; -- 2.55.0