rtc; pcf2123: fix possible alarm race condition
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 19 Aug 2019 18:26:49 +0000 (20:26 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Tue, 20 Aug 2019 19:42:05 +0000 (21:42 +0200)
Clear the flag after disabling the alarm to ensure the alarm doesn't fire
between clearing the flag and disabling the alarm.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20190819182656.29744-2-alexandre.belloni@bootlin.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-pcf2123.c

index 5f604d8..829d7a2 100644 (file)
@@ -274,13 +274,13 @@ static int pcf2123_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
 
        dev_dbg(dev, "%s: alm is %ptR\n", __func__, &alm->time);
 
-       /* Ensure alarm flag is clear */
-       ret = regmap_update_bits(pdata->map, PCF2123_REG_CTRL2, CTRL2_AF, 0);
+       /* Disable alarm interrupt */
+       ret = regmap_update_bits(pdata->map, PCF2123_REG_CTRL2, CTRL2_AIE, 0);
        if (ret)
                return ret;
 
-       /* Disable alarm interrupt */
-       ret = regmap_update_bits(pdata->map, PCF2123_REG_CTRL2, CTRL2_AIE, 0);
+       /* Ensure alarm flag is clear */
+       ret = regmap_update_bits(pdata->map, PCF2123_REG_CTRL2, CTRL2_AF, 0);
        if (ret)
                return ret;