From mboxrd@z Thu Jan 1 00:00:00 1970 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 2029B3DD500 for ; Thu, 23 Jul 2026 19:41:51 +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=1784835715; cv=none; b=hdp+xxD5uDjyvCoAB0hpltmOotp4LTbD5rYIFxG8FFsbbZh69GPVILahtwtu/5wvc8dOA/uxwgIuQZeMec2ztQ/4rnmrAVJUBHgOpGOikNtVpb4BznU2zMPrwu3rcLugbjHN29pGzFQ+TxNPPkMw9zFWJXoDfMJFdJUdCx3pLBk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784835715; c=relaxed/simple; bh=LY0yMgZJBPQvaHgbjl3dveOux4Be0xwL6G2Zen77Log=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QivpEDGT9bth5fnZ3nz3kbo4ykJF3U7iJjSgi38YV2/0w3T6r+kmORSjzQ/XBph9Qz4e0z86p0RFLpQqlFSMGYguWvVLwTzW5DmLDpg7MMRmla2b7hOQK9+LtN+ZgJstrxweQvAksd29ZMGpa6dX2oZVUN7JXBDEryfiyV2oCno= 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=K8MC9VW5; 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="K8MC9VW5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1784835708; bh=LY0yMgZJBPQvaHgbjl3dveOux4Be0xwL6G2Zen77Log=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=K8MC9VW5GsaRRF1DRBmLNZqNCtvqHgPVk8eDSIb1mIa/SbNtOrx/afZgJlPhL1YiX 8dnaa/ctKcSP98bAG2S2s1uDleDhkphD/FCZUXSUapKvTL+4PgTV+dl9VqOxdZvsHr 5Bve6LF14dRH05F7t12eCaS4wpxuNJz8iJ+aifuufqXk4pnMjP5ksKEIdhnDJaduEI SXUUXJGbv9LBaiftIs73qmXMx1Wmj2OSsZZFbvfROKYUlYdNZU94eLC7t5YXEPO1Bt jdM4I4yIoNZAh+MIE9GWHLFuHn6rJaSux6WAOEnIZunRKCWqRyp41QbcCa/uaIqd5I wCnytMFhNtdug== 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 ED92517E0C7E; Thu, 23 Jul 2026 21:41:47 +0200 (CEST) From: Cristian Ciocaltea Date: Thu, 23 Jul 2026 22:41:45 +0300 Subject: [PATCH v5 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: <20260723-hdptx-clk-fixes-v5-2-8e786067865f@collabora.com> References: <20260723-hdptx-clk-fixes-v5-0-8e786067865f@collabora.com> In-Reply-To: <20260723-hdptx-clk-fixes-v5-0-8e786067865f@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 | 11 ++++++++--- 1 file changed, 8 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..44e99343f249 100644 --- a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c +++ b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c @@ -2270,10 +2270,15 @@ 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) { + 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