Skip to content

Commit

Permalink
rtc: ds1307: ds3231 temperature s16 overflow
Browse files Browse the repository at this point in the history
while retrieving temperature from ds3231, the result may be overflow
since s16 is too small for a multiplication with 250.

ie. if temp_buf[0] == 0x2d, the result (s16 temp) will be negative.

Signed-off-by: Akinobu Mita <[email protected]>
Tested-by: Michael Tatarinov <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
  • Loading branch information
Zhuang Yuyao authored and alexandrebelloni committed Apr 21, 2016
1 parent 00c9329 commit 9a3dce6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/rtc/rtc-ds1307.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ static void ds1307_trickle_of_init(struct i2c_client *client,
* A user-initiated temperature conversion is not started by this function,
* so the temperature is updated once every 64 seconds.
*/
static int ds3231_hwmon_read_temp(struct device *dev, s16 *mC)
static int ds3231_hwmon_read_temp(struct device *dev, s32 *mC)
{
struct ds1307 *ds1307 = dev_get_drvdata(dev);
u8 temp_buf[2];
Expand Down Expand Up @@ -892,7 +892,7 @@ static ssize_t ds3231_hwmon_show_temp(struct device *dev,
struct device_attribute *attr, char *buf)
{
int ret;
s16 temp;
s32 temp;

ret = ds3231_hwmon_read_temp(dev, &temp);
if (ret)
Expand Down

0 comments on commit 9a3dce6

Please sign in to comment.