Skip to contentSkip to conversation

rtc: ds1307: ds3231 temperature s16 overflow

PATCH Applied Akinobu Mita 3 participants 7 messages Apr 18, 2016 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: ds1307: ds3231 temperature s16 overflow

From: Zhuang Yuyao <[email protected]>

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.

Cc Zhuang Yuyao <[email protected]>
Cc Zhuang Yuyao <[email protected]>
Cc Michael Tatarinov <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
---
 drivers/rtc/rtc-ds1307.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-ds1307.c +2 -2
index cb0ffa8..90d1e5a 100644
@@ -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)
Signature · 12 lines
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
#1 lore raw

Hello

Thanks!
I haven't tested the patch yet but I already have a question. What about s16 in ds3231_hwmon_show_temp()?

2016-04-18 4:21 GMT+04:00, Akinobu Mita <[email protected]>:

Quoted 45 lines

From: Zhuang Yuyao <[email protected]>

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.

Cc Zhuang Yuyao <[email protected]>
Cc Zhuang Yuyao <[email protected]>
Cc Michael Tatarinov <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
---
 drivers/rtc/rtc-ds1307.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-ds1307.c +1 -1
index cb0ffa8..90d1e5a 100644
@@ -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);
drivers/rtc/rtc-ds1307.c +1 -1
 	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

Signature · 9 lines
-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
#2 lore raw

sorry, I realized my mistake

2016-04-18 8:33 GMT+04:00, Michael Tatarinov <[email protected]>:

Quoted 54 lines

Hello

Thanks!
I haven't tested the patch yet but I already have a question. What about s16 in ds3231_hwmon_show_temp()?

2016-04-18 4:21 GMT+04:00, Akinobu Mita <[email protected]>:

Quoted 45 lines

From: Zhuang Yuyao <[email protected]>

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.

Cc Zhuang Yuyao <[email protected]>
Cc Zhuang Yuyao <[email protected]>
Cc Michael Tatarinov <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
---
 drivers/rtc/rtc-ds1307.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-ds1307.c +1 -1
index cb0ffa8..90d1e5a 100644
@@ -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);
drivers/rtc/rtc-ds1307.c +1 -1
 	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

Signature · 9 lines
-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
#3 lore raw
In reply to Akinobu Mita

Thanks.

I'm testing the patch, it workins as expected.

$ cat /sys/devices/platform/soc/20804000.i2c/i2c-1/1-0068/hwmon/hwmon1/temp1_input
33000

2016-04-18 4:21 GMT+04:00, Akinobu Mita <[email protected]>:

Quoted 6 lines

From: Zhuang Yuyao <[email protected]>

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.

Signature · 9 lines
-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
#4 lore raw

2016-04-18 19:24 GMT+09:00 Michael Tatarinov <[email protected]>:

Quoted 6 lines

Thanks.

I'm testing the patch, it workins as expected.

$ cat /sys/devices/platform/soc/20804000.i2c/i2c-1/1-0068/hwmon/hwmon1/temp1_input
33000

Thanks for testing!

Can I put your Tested-by tag in this patch?

Signature · 9 lines
-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
#5 lore raw

2016-04-18 17:05 GMT+04:00, Akinobu Mita <[email protected]>:

Quoted 10 lines

2016-04-18 19:24 GMT+09:00 Michael Tatarinov <[email protected]>:

Quoted 7 lines

Thanks.

I'm testing the patch, it workins as expected.

$ cat
/sys/devices/platform/soc/20804000.i2c/i2c-1/1-0068/hwmon/hwmon1/temp1_input
33000

Thanks for testing!

Thanks for original patch and fix. :)

Quoted 1 line

Can I put your Tested-by tag in this patch?

Yes.

Signature · 9 lines
-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
#6 lore raw
In reply to Akinobu Mita
Quoted 13 lines · Akinobu Mita

From: Zhuang Yuyao <[email protected]>

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.

Cc Zhuang Yuyao <[email protected]>
Cc Zhuang Yuyao <[email protected]>
Cc Michael Tatarinov <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Alexandre Belloni <[email protected]>
Quoted 4 lines
---
 drivers/rtc/rtc-ds1307.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks.

Signature · 14 lines
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

-- 
-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.