ARM: tegra12: clock: Fix round rate error checking
Kaz Fukuoka [Wed, 28 Aug 2013 00:21:57 +0000 (17:21 -0700)]
Some callers of clk_round_rate() API assume that return signed value
is negative in case of error, and positive if API succeeded. The latter
is not true when the clock rate crosses ~2.1 GHz (2,147,483,647 Hz)
boundary on 32-bit machine. To prevent false bailing out on 2.1GHz and
above rates callers of round rate API should cast the rounded rate as
unsigned, and use IS_ERR_VALUE() macro to detect errors instead of
checking sign of the returned value.

Change-Id: I675f18473a0fe03b3a0b26978784e25dfd7c0280
Signed-off-by: Kaz Fukuoka <kfukuoka@nvidia.com>
Reviewed-on: http://git-master/r/267572
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Aleksandr Frid <afrid@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>

arch/arm/mach-tegra/tegra12_clocks.c

index e1d9906..2638fe5 100644 (file)
@@ -4648,11 +4648,11 @@ static void tegra12_emc_clk_init(struct clk *c)
 static long tegra12_emc_clk_round_updown(struct clk *c, unsigned long rate,
                                         bool up)
 {
-       long new_rate = max(rate, c->min_rate);
+       unsigned long new_rate = max(rate, c->min_rate);
 
        /* FIXME: emc updown rounding */
        new_rate = tegra_emc_round_rate(new_rate);
-       if (new_rate < 0)
+       if (IS_ERR_VALUE(new_rate))
                new_rate = c->max_rate;
 
        return new_rate;