[PATCH 1/2] clk: tegra: periph: Fix error handling and resolve unsigned compare warning

Pei Xiao posted 2 patches 3 months ago
[PATCH 1/2] clk: tegra: periph: Fix error handling and resolve unsigned compare warning
Posted by Pei Xiao 3 months ago
./drivers/clk/tegra/clk-periph.c:59:5-9: WARNING:
	Unsigned expression compared with zero: rate < 0

The unsigned long 'rate' variable caused:
- Incorrect handling of negative errors
- Compile warning: "Unsigned expression compared with zero"

Fix by changing to long type and adding req->rate cast.

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
 drivers/clk/tegra/clk-periph.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/tegra/clk-periph.c b/drivers/clk/tegra/clk-periph.c
index 0626650a7011..c9fc52a36fce 100644
--- a/drivers/clk/tegra/clk-periph.c
+++ b/drivers/clk/tegra/clk-periph.c
@@ -51,7 +51,7 @@ static int clk_periph_determine_rate(struct clk_hw *hw,
 	struct tegra_clk_periph *periph = to_clk_periph(hw);
 	const struct clk_ops *div_ops = periph->div_ops;
 	struct clk_hw *div_hw = &periph->divider.hw;
-	unsigned long rate;
+	long rate;
 
 	__clk_hw_set_clk(div_hw, hw);
 
@@ -59,7 +59,7 @@ static int clk_periph_determine_rate(struct clk_hw *hw,
 	if (rate < 0)
 		return rate;
 
-	req->rate = rate;
+	req->rate = (unsigned long)rate;
 	return 0;
 }
 
-- 
2.25.1
Re: [PATCH 1/2] clk: tegra: periph: Fix error handling and resolve unsigned compare warning
Posted by Stephen Boyd 2 months, 2 weeks ago
Quoting Pei Xiao (2025-07-09 00:37:13)
> ./drivers/clk/tegra/clk-periph.c:59:5-9: WARNING:
>         Unsigned expression compared with zero: rate < 0
> 
> The unsigned long 'rate' variable caused:
> - Incorrect handling of negative errors
> - Compile warning: "Unsigned expression compared with zero"
> 
> Fix by changing to long type and adding req->rate cast.
> 
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> ---

Applied to clk-next
Re: [PATCH 1/2] clk: tegra: periph: Fix error handling and resolve unsigned compare warning
Posted by Thierry Reding 3 months ago
On Wed, Jul 09, 2025 at 03:37:13PM +0800, Pei Xiao wrote:
> ./drivers/clk/tegra/clk-periph.c:59:5-9: WARNING:
> 	Unsigned expression compared with zero: rate < 0
> 
> The unsigned long 'rate' variable caused:
> - Incorrect handling of negative errors
> - Compile warning: "Unsigned expression compared with zero"
> 
> Fix by changing to long type and adding req->rate cast.
> 
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> ---
>  drivers/clk/tegra/clk-periph.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>