Skip to contentSkip to conversation

arm/mach-tegra: fix unsigned calcs

PATCH Applied Kulikov Vasiliy 3 participants 3 messages Jul 15, 2010 – Jul 20, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/8 arm/mach-tegra: fix unsigned calcs

divider_u71 is unsigned, so this check is buggy:
if (divider_u71 - 2 > 255 || divider_u71 - 2 < 0)

If divider_u71 is 0 or 1 both checks are lying. So, it does not produce a buggy answer, but it is confusing.

---
 arch/arm/mach-tegra/tegra2_clocks.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/mach-tegra/tegra2_clocks.c +1 -1
index 4261632..64df5b4 100644
@@ -149,7 +149,7 @@ static int clk_div71_get_divider(struct clk *c, unsigned long rate)
 
 	divider_u71 = DIV_ROUND_UP(c->rate * 2, rate);
 
-	if (divider_u71 - 2 > 255 || divider_u71 - 2 < 0)
+	if (divider_u71 > 2 + 255 || divider_u71 < 2)
 		return -EINVAL;
 
 	return divider_u71 - 2;
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 5 lines · Kulikov Vasiliy

divider_u71 is unsigned, so this check is buggy:
if (divider_u71 - 2 > 255 || divider_u71 - 2 < 0)

If divider_u71 is 0 or 1 both checks are lying. So, it does not produce a buggy answer, but it is confusing.

Hi Kulikov,
Thanks for the patch. This problem has been fixed in another patch in the linux-tegra tree, I'll post it for review and update the linux-next tree soon.

Colin Cross

#2 lore raw
Quoted 8 lines · Colin Cross
Quoted 5 lines · Kulikov Vasiliy

divider_u71 is unsigned, so this check is buggy:
if (divider_u71 - 2 > 255 || divider_u71 - 2 < 0)

If divider_u71 is 0 or 1 both checks are lying. So, it does not produce a buggy answer, but it is confusing.

Hi Kulikov,

The first name is Vasiliy :)

Quoted 10 lines

Thanks for the patch. This problem has been fixed in another patch in the linux-tegra tree, I'll post it for review and update the linux-next tree soon.

Colin Cross

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Signature · 2 lines
Sincerely yours,
Mike.