]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
media: i2c: max2175: use 64-bit arithmetic instead of 32-bit
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Tue, 6 Feb 2018 16:47:37 +0000 (11:47 -0500)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Mon, 26 Feb 2018 13:08:15 +0000 (08:08 -0500)
Add suffix LL to constant 2 in order to give the compiler complete
information about the proper arithmetic to use. Notice that this
constant is used in a context that expects an expression of type
s64 (64 bits, signed).

The expression 2 * (clock_rate - abs_nco_freq) is currently being
evaluated using 32-bit arithmetic.

Addresses-Coverity-ID: 1446589 ("Unintentional integer overflow")

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/i2c/max2175.c

index 2f1966bdc47329ef1f897154b3824ea7866da35f..87cba15b2977b7711c710e23da0523702b37b453 100644 (file)
@@ -643,7 +643,7 @@ static int max2175_set_nco_freq(struct max2175 *ctx, s32 nco_freq)
        if (abs_nco_freq < clock_rate / 2) {
                nco_val_desired = 2 * nco_freq;
        } else {
-               nco_val_desired = 2 * (clock_rate - abs_nco_freq);
+               nco_val_desired = 2LL * (clock_rate - abs_nco_freq);
                if (nco_freq < 0)
                        nco_val_desired = -nco_val_desired;
        }