From: sashiko-bot@kernel.org
To: "Cristian Ciocaltea" <cristian.ciocaltea@collabora.com>
Cc: vkoul@kernel.org, olteanv@gmail.com,
linux-phy@lists.infradead.org, neil.armstrong@linaro.org
Subject: Re: [PATCH v5 02/10] phy: rockchip: samsung-hdptx: Prevent divide-by-zero when computing clk rate
Date: Thu, 23 Jul 2026 19:55:46 +0000 [thread overview]
Message-ID: <20260723195546.7E6B41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723-hdptx-clk-fixes-v5-2-8e786067865f@collabora.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Clock rate determination fails in FRL mode due to returning raw rate instead of 0.
- [High] Unintended state mutation of `hdmi_cfg` during `determine_rate` read queries.
--
--- Patch [2]: [PATCH v5 02/10] phy: rockchip: samsung-hdptx: Prevent divide-by-zero when computing clk rate ---
commit 3aac52ab862cd2c54c76fff590e3524e49936631
Author: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
phy: rockchip: samsung-hdptx: Prevent divide-by-zero when computing clk rate
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. Provide the necessary sanitization to avoid
trusting the hardware state.
Link: https://sashiko.dev/#/patchset/20260611-hdptx-clk-fixes-v3-0-67b1b0c00e16@collabora.com?part=1
> diff --git a/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c b/drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c
> index 710603afff866..44e99343f2499 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;
While reviewing this patch, I noticed a couple of pre-existing issues in the
adjacent rk_hdptx_phy_clk_determine_rate() function:
drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c:rk_hdptx_phy_clk_determine_rate() {
...
if (hdptx->hdmi_cfg.mode == PHY_HDMI_MODE_FRL)
return hdptx->hdmi_cfg.rate;
[Severity: High]
This isn't a bug introduced by this patch, but does this violate the
determine_rate API contract?
When the PHY is in FRL mode, the callback directly returns
hdptx->hdmi_cfg.rate (e.g., up to 3.2GHz). However, the Common Clock
Framework expects determine_rate to return 0 on success and update
req->rate.
Returning these massive positive integers casts them to a signed 32-bit int,
causing rates like 3.2GHz to overflow into a negative error code
(e.g., -1094277376).
Will clk_core_determine_round_nolock() propagate this negative error,
causing clk_set_rate() to abort and fail completely for FRL modes?
...
int ret = rk_hdptx_phy_verify_hdmi_config(hdptx, &hdmi, &hdptx->hdmi_cfg);
[Severity: High]
This is a pre-existing issue, but does this mutate the driver's internal
PHY configuration state during what should be a stateless query?
The determine_rate clock operation must be a stateless read query
(clk_round_rate). However, passing &hdptx->hdmi_cfg as the output parameter
to rk_hdptx_phy_verify_hdmi_config() modifies hdptx->hdmi_cfg.rate and bpc.
Since clk_round_rate can be called multiple times with different
hypothetical rates before any actual rate changes are committed, could
this corrupt the actual hardware tracking state?
If the rate change is subsequently aborted or clk_set_rate is called
with a different best rate, would hdptx->hdmi_cfg be left in an
inconsistent state, causing the actual hardware configuration to be
misconfigured?
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260723-hdptx-clk-fixes-v5-0-8e786067865f@collabora.com?part=2
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-07-23 19:55 UTC|newest]
Thread overview: 41+ 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 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 01/10] phy: rockchip: samsung-hdptx: Fix rate recalculation for high bpc Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 02/10] phy: rockchip: samsung-hdptx: Prevent divide-by-zero when computing clk rate Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:55 ` sashiko-bot [this message]
2026-07-23 21:40 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 03/10] phy: rockchip: samsung-hdptx: Guard against clk rate integer underflow Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:57 ` sashiko-bot
2026-07-23 21:22 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 04/10] phy: rockchip: samsung-hdptx: Fix rate recalculation for 3.2GHz FRL Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 05/10] phy: rockchip: samsung-hdptx: Handle uncommitted PHY config changes Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 20:00 ` sashiko-bot
2026-07-23 21:48 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 06/10] phy: rockchip: samsung-hdptx: Drop TMDS rate setup workaround Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:54 ` sashiko-bot
2026-07-23 20:50 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 07/10] phy: rockchip: samsung-hdptx: Consolidate consumer_put on error path Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 08/10] phy: rockchip: samsung-hdptx: Drop restrict_rate_change handling Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 09/10] phy: rockchip: samsung-hdptx: Simplify GRF access with FIELD_PREP_WM16() Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` [PATCH v5 10/10] phy: rockchip: samsung-hdptx: Consistently use bitfield macros Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
2026-07-23 19:41 ` Cristian Ciocaltea
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=20260723195546.7E6B41F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cristian.ciocaltea@collabora.com \
--cc=linux-phy@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=olteanv@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.