* [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
* [rtc-linux] Re: [PATCH] rtc: ds1307: ds3231 temperature s16 overflow
2016-04-18 0:21 [rtc-linux] [PATCH] rtc: ds1307: ds3231 temperature s16 overflow Akinobu Mita
@ 2016-04-18 4:33 ` Michael Tatarinov
2016-04-18 4:54 ` Michael Tatarinov
2016-04-18 10:24 ` Michael Tatarinov
2016-04-18 22:36 ` Alexandre Belloni
2 siblings, 1 reply; 7+ messages in thread
From: Michael Tatarinov @ 2016-04-18 4:33 UTC (permalink / raw)
To: Akinobu Mita
Cc: rtc-linux, Zhuang Yuyao, Zhuang Yuyao, Alessandro Zummo,
Alexandre Belloni
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 <akinobu.mita@gmail.com>:
> 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 [flat|nested] 7+ messages in thread
* [rtc-linux] Re: [PATCH] rtc: ds1307: ds3231 temperature s16 overflow
2016-04-18 4:33 ` [rtc-linux] " Michael Tatarinov
@ 2016-04-18 4:54 ` Michael Tatarinov
0 siblings, 0 replies; 7+ messages in thread
From: Michael Tatarinov @ 2016-04-18 4:54 UTC (permalink / raw)
To: Akinobu Mita
Cc: rtc-linux, Zhuang Yuyao, Zhuang Yuyao, Alessandro Zummo,
Alexandre Belloni
sorry, I realized my mistake
2016-04-18 8:33 GMT+04:00, Michael Tatarinov <kukabu@gmail.com>:
> 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 <akinobu.mita@gmail.com>:
>> 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 [flat|nested] 7+ messages in thread
* [rtc-linux] Re: [PATCH] rtc: ds1307: ds3231 temperature s16 overflow
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 10:24 ` Michael Tatarinov
2016-04-18 13:05 ` Akinobu Mita
2016-04-18 22:36 ` Alexandre Belloni
2 siblings, 1 reply; 7+ messages in thread
From: Michael Tatarinov @ 2016-04-18 10:24 UTC (permalink / raw)
To: Akinobu Mita
Cc: rtc-linux, Zhuang Yuyao, Zhuang Yuyao, Alessandro Zummo,
Alexandre Belloni
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 <akinobu.mita@gmail.com>:
> 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.
--
--
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 [flat|nested] 7+ messages in thread
* [rtc-linux] Re: [PATCH] rtc: ds1307: ds3231 temperature s16 overflow
2016-04-18 10:24 ` Michael Tatarinov
@ 2016-04-18 13:05 ` Akinobu Mita
2016-04-18 14:44 ` Michael Tatarinov
0 siblings, 1 reply; 7+ messages in thread
From: Akinobu Mita @ 2016-04-18 13:05 UTC (permalink / raw)
To: Michael Tatarinov
Cc: rtc-linux, Zhuang Yuyao, Zhuang Yuyao, Alessandro Zummo,
Alexandre Belloni
2016-04-18 19:24 GMT+09:00 Michael Tatarinov <kukabu@gmail.com>:
> 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?
--
--
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 [flat|nested] 7+ messages in thread
* [rtc-linux] Re: [PATCH] rtc: ds1307: ds3231 temperature s16 overflow
2016-04-18 13:05 ` Akinobu Mita
@ 2016-04-18 14:44 ` Michael Tatarinov
0 siblings, 0 replies; 7+ messages in thread
From: Michael Tatarinov @ 2016-04-18 14:44 UTC (permalink / raw)
To: Akinobu Mita
Cc: rtc-linux, Zhuang Yuyao, Zhuang Yuyao, Alessandro Zummo,
Alexandre Belloni
2016-04-18 17:05 GMT+04:00, Akinobu Mita <akinobu.mita@gmail.com>:
> 2016-04-18 19:24 GMT+09:00 Michael Tatarinov <kukabu@gmail.com>:
>> 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. :)
> Can I put your Tested-by tag in this patch?
Yes.
--
--
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 [flat|nested] 7+ messages in thread
* [rtc-linux] Re: [PATCH] rtc: ds1307: ds3231 temperature s16 overflow
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 10:24 ` Michael Tatarinov
@ 2016-04-18 22:36 ` Alexandre Belloni
2 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2016-04-18 22:36 UTC (permalink / raw)
To: Akinobu Mita
Cc: rtc-linux, Zhuang Yuyao, Zhuang Yuyao, Michael Tatarinov,
Alessandro Zummo
On 18/04/2016 at 09:21:42 +0900, Akinobu Mita wrote :
> 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(-)
>
Applied, thanks.
--
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 rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [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.