Skip to content

Commit 79784c8

Browse files
cris-magregkh
authored andcommitted
clk: scmi: Fix clock rate rounding
[ Upstream commit d0c81a3 ] While the do_div() helper used for rounding expects its divisor argument to be a 32bits quantity, the currently provided divisor parameter is a 64bit value that, as a consequence, is silently truncated and a possible source of bugs. Fix by using the proper div64_ul helper. Cc: Michael Turquette <mturquette@baylibre.com> Cc: Stephen Boyd <sboyd@kernel.org> Cc: linux-clk@vger.kernel.org Fixes: 7a8655e ("clk: scmi: Fix the rounding of clock rate") Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://patch.msgid.link/20260508153300.2224715-2-cristian.marussi@arm.com Reviewed-by: Brian Masney <bmasney@redhat.com> Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c10d7a8 commit 79784c8

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/clk/clk-scmi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <linux/device.h>
1010
#include <linux/err.h>
1111
#include <linux/of.h>
12+
#include <linux/math64.h>
1213
#include <linux/module.h>
1314
#include <linux/scmi_protocol.h>
14-
#include <asm/div64.h>
1515

1616
static const struct scmi_clk_proto_ops *scmi_proto_clk_ops;
1717

@@ -61,7 +61,7 @@ static long scmi_clk_round_rate(struct clk_hw *hw, unsigned long rate,
6161

6262
ftmp = rate - fmin;
6363
ftmp += clk->info->range.step_size - 1; /* to round up */
64-
do_div(ftmp, clk->info->range.step_size);
64+
ftmp = div64_ul(ftmp, clk->info->range.step_size);
6565

6666
return ftmp * clk->info->range.step_size + fmin;
6767
}

0 commit comments

Comments
 (0)