From: Vinod Koul <vkoul@kernel.org>
To: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Cc: Manivannan Sadhasivam <mani@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Heiko Stuebner <heiko@sntech.de>,
Algea Cao <algea.cao@rock-chips.com>,
Dmitry Baryshkov <lumag@kernel.org>,
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 <sashiko-bot@kernel.org>,
Diederik de Haas <diederik@cknow-tech.com>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
Andy Yan <andy.yan@rock-chips.com>
Subject: Re: [PATCH v5 02/10] phy: rockchip: samsung-hdptx: Prevent divide-by-zero when computing clk rate
Date: Tue, 11 Aug 2026 16:54:23 +0530 [thread overview]
Message-ID: <ansGZ9LUA7ItYHe7@vaman> (raw)
In-Reply-To: <605f96b2-709c-49f6-9446-49ed3bff7d96@collabora.com>
On 07-08-26, 17:19, Cristian Ciocaltea wrote:
> Hi Mani,
>
> On 8/7/26 3:56 PM, Manivannan Sadhasivam wrote:
> > On Thu, Jul 23, 2026 at 10:41:45PM +0300, Cristian Ciocaltea wrote:
> >> 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 <sashiko-bot@kernel.org>
> >> 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 <diederik@cknow-tech.com> # NanoPC-T6 LTS
> >> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> >> Reviewed-by: Andy Yan <andy.yan@rock-chips.com>
> >> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
> >> ---
> >> 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");
> >
> > If the hardware state is invalid, why can't this be a hard failure?
>
> This is an internal helper called from the .recalc_rate clk_op, which tries to
> compute the current rate by reading back the hardware state.
>
> Since .recalc_rate returns unsigned long, we cannot propagate errors to the
> caller. However, per the clk_ops documentation, the driver is expected to
> return 0 if it cannot figure out the rate.
>
> Moreover, this condition isn't really fatal, as it only means the PLL
> configuration currently stored in hardware can't be translated into a rate. The
> next .set_rate should program a valid configuration and help with the recovery.
This is a good explanation which may not be obvious to everyone. I would
think that it would be good idea to add a comment for this here
--
~Vinod
next prev parent reply other threads:[~2026-08-11 11:24 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 19:41 [PATCH v5 00/10] phy: rockchip: samsung-hdptx: Clock fixes and API transition cleanups Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 01/10] phy: rockchip: samsung-hdptx: Fix rate recalculation for high bpc Cristian Ciocaltea
2026-08-07 12:58 ` Manivannan Sadhasivam
2026-07-23 19:41 ` [PATCH v5 02/10] phy: rockchip: samsung-hdptx: Prevent divide-by-zero when computing clk rate Cristian Ciocaltea
2026-08-07 12:56 ` Manivannan Sadhasivam
2026-08-07 14:19 ` Cristian Ciocaltea
2026-08-11 11:24 ` Vinod Koul [this message]
2026-08-11 15:51 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 03/10] phy: rockchip: samsung-hdptx: Guard against clk rate integer underflow Cristian Ciocaltea
2026-08-07 12:56 ` Manivannan Sadhasivam
2026-07-23 19:41 ` [PATCH v5 04/10] phy: rockchip: samsung-hdptx: Fix rate recalculation for 3.2GHz FRL Cristian Ciocaltea
2026-08-07 12:57 ` Manivannan Sadhasivam
2026-07-23 19:41 ` [PATCH v5 05/10] phy: rockchip: samsung-hdptx: Handle uncommitted PHY config changes Cristian Ciocaltea
2026-08-07 13:04 ` Manivannan Sadhasivam
2026-08-07 14:22 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 06/10] phy: rockchip: samsung-hdptx: Drop TMDS rate setup workaround Cristian Ciocaltea
2026-08-07 13:06 ` Manivannan Sadhasivam
2026-07-23 19:41 ` [PATCH v5 07/10] phy: rockchip: samsung-hdptx: Consolidate consumer_put on error path Cristian Ciocaltea
2026-08-07 13:07 ` Manivannan Sadhasivam
2026-07-23 19:41 ` [PATCH v5 08/10] phy: rockchip: samsung-hdptx: Drop restrict_rate_change handling Cristian Ciocaltea
2026-08-07 13:08 ` Manivannan Sadhasivam
2026-07-23 19:41 ` [PATCH v5 09/10] phy: rockchip: samsung-hdptx: Simplify GRF access with FIELD_PREP_WM16() Cristian Ciocaltea
2026-08-07 13:11 ` Manivannan Sadhasivam
2026-07-23 19:41 ` [PATCH v5 10/10] phy: rockchip: samsung-hdptx: Consistently use bitfield macros Cristian Ciocaltea
2026-08-07 13:12 ` Manivannan Sadhasivam
2026-08-11 17:03 ` [PATCH v5 00/10] phy: rockchip: samsung-hdptx: Clock fixes and API transition cleanups Vinod Koul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ansGZ9LUA7ItYHe7@vaman \
--to=vkoul@kernel.org \
--cc=algea.cao@rock-chips.com \
--cc=andy.yan@rock-chips.com \
--cc=cristian.ciocaltea@collabora.com \
--cc=diederik@cknow-tech.com \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=heiko@sntech.de \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=lumag@kernel.org \
--cc=mani@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=sashiko-bot@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox