From: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
To: <linux-clk@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <git@amd.com>, Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Michal Simek <michal.simek@amd.com>,
Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>,
<devicetree@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>
Subject: [PATCH v2 7/8] clk: clocking-wizard: Fix division by zero and unbounded register write
Date: Thu, 9 Jul 2026 16:44:02 +0530 [thread overview]
Message-ID: <20260709111403.1579159-8-shubhrajyoti.datta@amd.com> (raw)
In-Reply-To: <20260709111403.1579159-1-shubhrajyoti.datta@amd.com>
1. clk_wzrd_determine_rate(): DIV_ROUND_CLOSEST() can return 0 when
the requested rate greatly exceeds the parent rate, causing a
division by zero on the subsequent parent_rate / div. Clamp div
to a minimum of 1.
2. clk_wzrd_dynamic_reconfig(): min_t() result was not assigned back
to value, so the cap to WZRD_DR_MAX_INT_DIV_VALUE was never applied
before the register write.
3. clk_wzrd_get_divisors() and clk_wzrd_get_divisors_ver(): If rate is
0, DIV_ROUND_CLOSEST_ULL divides by zero. Return -EINVAL early.
Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
---
Changes in v2:
Patch added
drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
index 381e396aef0e..289c32ab5cd8 100644
--- a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
+++ b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
@@ -296,7 +296,7 @@ static int clk_wzrd_dynamic_reconfig(struct clk_hw *hw, unsigned long rate,
value = DIV_ROUND_CLOSEST(parent_rate, rate);
/* Cap the value to max */
- min_t(u32, value, WZRD_DR_MAX_INT_DIV_VALUE);
+ value = min_t(u32, value, WZRD_DR_MAX_INT_DIV_VALUE);
/* Set divisor and clear phase offset */
writel(value, div_addr);
@@ -334,6 +334,8 @@ static int clk_wzrd_determine_rate(struct clk_hw *hw,
* achievable
*/
div = DIV_ROUND_CLOSEST(req->best_parent_rate, req->rate);
+ if (!div)
+ div = 1;
req->rate = req->best_parent_rate / div;
@@ -348,6 +350,9 @@ static int clk_wzrd_get_divisors_ver(struct clk_hw *hw, unsigned long rate,
u32 m, d, o;
u32 mmin, mmax, dmin, dmax, omin, omax;
+ if (!rate)
+ return -EINVAL;
+
mmin = VER_WZRD_M_MIN;
mmax = VER_WZRD_M_MAX;
dmin = VER_WZRD_D_MIN;
@@ -390,6 +395,9 @@ static int clk_wzrd_get_divisors(struct clk_hw *hw, unsigned long rate,
u64 m, d, o;
u64 mmin, mmax, dmin, dmax, omin, omax, mdmin, mdmax;
+ if (!rate)
+ return -EINVAL;
+
mmin = WZRD_M_MIN << 3;
mmax = WZRD_M_MAX << 3;
dmin = WZRD_D_MIN;
--
2.34.1
next prev parent reply other threads:[~2026-07-09 11:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 11:13 [PATCH v2 0/8] clk: clocking-wizard: Add static-config clock provider support Shubhrajyoti Datta
2026-07-09 11:13 ` [PATCH v2 1/8] dt-bindings: clock: clocking-wizard: Add static-config mode support Shubhrajyoti Datta
2026-07-09 11:13 ` [PATCH v2 2/8] clk: clocking-wizard: Do not map the memory for static-config Shubhrajyoti Datta
2026-07-09 11:28 ` sashiko-bot
2026-07-09 11:13 ` [PATCH v2 3/8] clk: clocking-wizard: Move clk_in1 acquisition before static-config check Shubhrajyoti Datta
2026-07-09 11:25 ` sashiko-bot
2026-07-09 11:13 ` [PATCH v2 4/8] clk: clocking-wizard: Add static-config clock provider support Shubhrajyoti Datta
2026-07-09 11:26 ` sashiko-bot
2026-07-09 11:14 ` [PATCH v2 5/8] clk: clocking-wizard: Skip s_axi_aclk for static-config Shubhrajyoti Datta
2026-07-09 11:28 ` sashiko-bot
2026-07-09 11:14 ` [PATCH v2 6/8] clk: clocking-wizard: Use dev_err_probe() when mapping registers Shubhrajyoti Datta
2026-07-09 11:25 ` sashiko-bot
2026-07-09 11:14 ` Shubhrajyoti Datta [this message]
2026-07-09 11:28 ` [PATCH v2 7/8] clk: clocking-wizard: Fix division by zero and unbounded register write sashiko-bot
2026-07-09 11:14 ` [PATCH v2 8/8] clk: clocking-wizard: Use separate notifier_block for each clock Shubhrajyoti Datta
2026-07-09 11:20 ` sashiko-bot
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=20260709111403.1579159-8-shubhrajyoti.datta@amd.com \
--to=shubhrajyoti.datta@amd.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=git@amd.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=mturquette@baylibre.com \
--cc=robh@kernel.org \
--cc=sboyd@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