Skip to content

Commit

Permalink
hwmon: (sht15) Fix integer overflow in humidity calculation
Browse files Browse the repository at this point in the history
An integer overflow occurs in the calculation of RHlinear when the
relative humidity is greater than around 30%. The consequence is a subtle
(but noticeable) error in the resulting humidity measurement.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: stable@kernel.org
Cc: Jonathan Cameron <jic23@cam.ac.uk>
  • Loading branch information
vivien authored and Jean Delvare committed Mar 21, 2011
1 parent 396bd76 commit ccd32e7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/hwmon/sht15.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ static inline int sht15_calc_humid(struct sht15_data *data)

const int c1 = -4;
const int c2 = 40500; /* x 10 ^ -6 */
const int c3 = -2800; /* x10 ^ -9 */
const int c3 = -28; /* x 10 ^ -7 */

RHlinear = c1*1000
+ c2 * data->val_humid/1000
+ (data->val_humid * data->val_humid * c3)/1000000;
+ (data->val_humid * data->val_humid * c3) / 10000;
return (temp - 25000) * (10000 + 80 * data->val_humid)
/ 1000000 + RHlinear;
}
Expand Down

0 comments on commit ccd32e7

Please sign in to comment.