diff mbox

[v4,3/7] rtc: ds3232: fix read on /dev/rtc after RTC_AIE_ON

Message ID 1457278073-11627-3-git-send-email-akinobu.mita@gmail.com
State Accepted
Headers show

Commit Message

Akinobu Mita March 6, 2016, 3:27 p.m. UTC
The rtctest (tools/testing/selftests/timers/rtctest.c) found that
reading ds3232 rtc device immediately return the value 0x20 (RTC_AF)
without waiting alarm interrupt.

This is because alarm_irq_enable() of ds3232 driver changes RTC_AF
flag in rtc->irq_data.  So calling ioctl with RTC_AIE_ON generates
invalid value in rtc device.

The lower-level driver should not touch rtc->irq_data directly.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Dennis Aberilla <denzzzhome@yahoo.com>
---
* No changes from the previous version

 drivers/rtc/rtc-ds3232.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Alexandre Belloni March 10, 2016, 6:25 a.m. UTC | #1
On 07/03/2016 at 00:27:49 +0900, Akinobu Mita wrote :
> The rtctest (tools/testing/selftests/timers/rtctest.c) found that
> reading ds3232 rtc device immediately return the value 0x20 (RTC_AF)
> without waiting alarm interrupt.
> 
> This is because alarm_irq_enable() of ds3232 driver changes RTC_AF
> flag in rtc->irq_data.  So calling ioctl with RTC_AIE_ON generates
> invalid value in rtc device.
> 
> The lower-level driver should not touch rtc->irq_data directly.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Alessandro Zummo <a.zummo@towertech.it>
> Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Cc: Dennis Aberilla <denzzzhome@yahoo.com>
> ---
> * No changes from the previous version
> 
>  drivers/rtc/rtc-ds3232.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 

This patch and all the following are applied, thanks.
diff mbox

Patch

diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index 81aa104..b27acea 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -272,7 +272,7 @@  out:
 	return ret;
 }
 
-static void ds3232_update_alarm(struct device *dev)
+static void ds3232_update_alarm(struct device *dev, unsigned int enabled)
 {
 	struct ds3232 *ds3232 = dev_get_drvdata(dev);
 	int control;
@@ -302,7 +302,7 @@  static void ds3232_update_alarm(struct device *dev)
 	if (ret)
 		goto unlock;
 
-	if (ds3232->rtc->irq_data & (RTC_AF | RTC_UF))
+	if (enabled || (ds3232->rtc->irq_data & RTC_UF))
 		/* enable alarm1 interrupt */
 		control |= DS3232_REG_CR_A1IE;
 	else
@@ -321,12 +321,8 @@  static int ds3232_alarm_irq_enable(struct device *dev, unsigned int enabled)
 	if (ds3232->irq <= 0)
 		return -EINVAL;
 
-	if (enabled)
-		ds3232->rtc->irq_data |= RTC_AF;
-	else
-		ds3232->rtc->irq_data &= ~RTC_AF;
+	ds3232_update_alarm(dev, enabled);
 
-	ds3232_update_alarm(dev);
 	return 0;
 }