All of lore.kernel.org
 help / color / mirror / Atom feed
* [rtc-linux] [PATCH] rtc: ds1307: ds3231 temperature s16 overflow
@ 2016-04-18  0:21 Akinobu Mita
  2016-04-18  4:33 ` [rtc-linux] " Michael Tatarinov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Akinobu Mita @ 2016-04-18  0:21 UTC (permalink / raw)
  To: rtc-linux
  Cc: Zhuang Yuyao, Akinobu Mita, Zhuang Yuyao, Michael Tatarinov,
	Alessandro Zummo, Alexandre Belloni

From: Zhuang Yuyao <mlistz@gmail.com>

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 <akinobu.mita@gmail.com>
Cc: Zhuang Yuyao <mlistz@gmail.com>
Cc: Zhuang Yuyao <zhuangyy@syan.com.cn>
Cc: Michael Tatarinov <kukabu@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/rtc/rtc-ds1307.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index cb0ffa8..90d1e5a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -863,7 +863,7 @@ out:
  * 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];
@@ -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)
-- 
2.5.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-04-18 22:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-18  0:21 [rtc-linux] [PATCH] rtc: ds1307: ds3231 temperature s16 overflow Akinobu Mita
2016-04-18  4:33 ` [rtc-linux] " Michael Tatarinov
2016-04-18  4:54   ` Michael Tatarinov
2016-04-18 10:24 ` Michael Tatarinov
2016-04-18 13:05   ` Akinobu Mita
2016-04-18 14:44     ` Michael Tatarinov
2016-04-18 22:36 ` Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.