[bug report] iio: light: add driver for MAX44009

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Robert Eshleman,

Commit 6aef699a7d7e ("iio: light: add driver for MAX44009") from Jan
31, 2019 (linux-next), leads to the following Smatch static checker
warning:

	drivers/iio/light/max44009.c:309 max44009_threshold_byte_from_fraction()
	warn: potential integer overflow 'integral * 1000' 's32min-7520256 * 1000'

drivers/iio/light/max44009.c
    299 static int max44009_threshold_byte_from_fraction(int integral, int fractional)
    300 {
    301         int mantissa, exp;
    302 
    303         if ((integral <= 0 && fractional <= 0) ||

I don't understand how negatives are handled here.  Was || intended
instead of &&?  These values come from the user via
iio_ev_value_store().

    304              integral > MAX44009_MAXIMUM_THRESHOLD ||
    305              (integral == MAX44009_MAXIMUM_THRESHOLD && fractional != 0))
    306                 return -EINVAL;
    307 
    308         /* Reverse scaling of fixed-point integral */
--> 309         mantissa = integral * MAX44009_SCALE_DENOMINATOR;

If integral were INT_MIN and fractional were any positive value then
this multiply would result in a integer wrapping bug.

    310         mantissa /= MAX44009_SCALE_NUMERATOR;
    311 
    312         /* Reverse scaling of fixed-point fractional */
    313         mantissa += fractional / MAX44009_FRACT_MULT *
    314                     (MAX44009_SCALE_DENOMINATOR / MAX44009_SCALE_NUMERATOR);
    315 
    316         for (exp = 0; mantissa > 0xff; exp++)
    317                 mantissa >>= 1;
    318 
    319         mantissa >>= 4;
    320         mantissa &= 0xf;
    321         exp <<= 4;
    322 
    323         return exp | mantissa;
    324 }

regards,
dan carpenter




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux