* [PATCH] clk: tegra: bpmp: Clamp clock rates on requests
@ 2020-10-21 10:10 Mikko Perttunen
2020-10-21 23:01 ` Sivaram Nair
0 siblings, 1 reply; 2+ messages in thread
From: Mikko Perttunen @ 2020-10-21 10:10 UTC (permalink / raw)
To: pdeschrijver, mturquette, sboyd, thierry.reding, jonathanh
Cc: linux-clk, linux-tegra, Sivaram Nair, Mikko Perttunen
From: Sivaram Nair <sivaramn@nvidia.com>
BPMP firmware ABI expects the rate inputs in int64_t. However,
tegra_bpmp_clk_round_rate() and tegra_bpmp_clk_set_rate() functions
directly assign 'unsigned long' inputs to a int64_t value causing
unexpected rounding errors.
Fix this by clipping the input rate to S64_MAX.
Signed-off-by: Sivaram Nair <sivaramn@nvidia.com>
[mperttunen: slight cleanup]
Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
drivers/clk/tegra/clk-bpmp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
index a66263b6490d..6ecf18f71c32 100644
--- a/drivers/clk/tegra/clk-bpmp.c
+++ b/drivers/clk/tegra/clk-bpmp.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
- * Copyright (C) 2016 NVIDIA Corporation
+ * Copyright (C) 2016-2020 NVIDIA Corporation
*/
#include <linux/clk-provider.h>
@@ -174,7 +174,7 @@ static long tegra_bpmp_clk_round_rate(struct clk_hw *hw, unsigned long rate,
int err;
memset(&request, 0, sizeof(request));
- request.rate = rate;
+ request.rate = min_t(u64, rate, S64_MAX);
memset(&msg, 0, sizeof(msg));
msg.cmd = CMD_CLK_ROUND_RATE;
@@ -256,7 +256,7 @@ static int tegra_bpmp_clk_set_rate(struct clk_hw *hw, unsigned long rate,
struct tegra_bpmp_clk_message msg;
memset(&request, 0, sizeof(request));
- request.rate = rate;
+ request.rate = min_t(u64, rate, S64_MAX);
memset(&msg, 0, sizeof(msg));
msg.cmd = CMD_CLK_SET_RATE;
--
2.28.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] clk: tegra: bpmp: Clamp clock rates on requests
2020-10-21 10:10 [PATCH] clk: tegra: bpmp: Clamp clock rates on requests Mikko Perttunen
@ 2020-10-21 23:01 ` Sivaram Nair
0 siblings, 0 replies; 2+ messages in thread
From: Sivaram Nair @ 2020-10-21 23:01 UTC (permalink / raw)
To: Mikko Perttunen
Cc: pdeschrijver, mturquette, sboyd, thierry.reding, jonathanh,
linux-clk, linux-tegra
On Wed, Oct 21, 2020 at 01:10:54PM +0300, Mikko Perttunen wrote:
> From: Sivaram Nair <sivaramn@nvidia.com>
>
> BPMP firmware ABI expects the rate inputs in int64_t. However,
> tegra_bpmp_clk_round_rate() and tegra_bpmp_clk_set_rate() functions
> directly assign 'unsigned long' inputs to a int64_t value causing
> unexpected rounding errors.
>
> Fix this by clipping the input rate to S64_MAX.
>
> Signed-off-by: Sivaram Nair <sivaramn@nvidia.com>
> [mperttunen: slight cleanup]
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> ---
> drivers/clk/tegra/clk-bpmp.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
> index a66263b6490d..6ecf18f71c32 100644
> --- a/drivers/clk/tegra/clk-bpmp.c
> +++ b/drivers/clk/tegra/clk-bpmp.c
> @@ -1,6 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0-only
> /*
> - * Copyright (C) 2016 NVIDIA Corporation
> + * Copyright (C) 2016-2020 NVIDIA Corporation
> */
>
> #include <linux/clk-provider.h>
> @@ -174,7 +174,7 @@ static long tegra_bpmp_clk_round_rate(struct clk_hw *hw, unsigned long rate,
> int err;
>
> memset(&request, 0, sizeof(request));
> - request.rate = rate;
> + request.rate = min_t(u64, rate, S64_MAX);
>
> memset(&msg, 0, sizeof(msg));
> msg.cmd = CMD_CLK_ROUND_RATE;
> @@ -256,7 +256,7 @@ static int tegra_bpmp_clk_set_rate(struct clk_hw *hw, unsigned long rate,
> struct tegra_bpmp_clk_message msg;
>
> memset(&request, 0, sizeof(request));
> - request.rate = rate;
> + request.rate = min_t(u64, rate, S64_MAX);
>
> memset(&msg, 0, sizeof(msg));
> msg.cmd = CMD_CLK_SET_RATE;
> --
> 2.28.0
>
Reviewed-by: Sivaram Nair
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-21 23:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-21 10:10 [PATCH] clk: tegra: bpmp: Clamp clock rates on requests Mikko Perttunen
2020-10-21 23:01 ` Sivaram Nair
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).