Skip to contentSkip to conversation

rtc: mxc_v2: unlock on error in mxc_rtc_set_alarm()

PATCH In review Dan Carpenter 2 participants 3 messages Mar 14, 2018 – Mar 15, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: mxc_v2: unlock on error in mxc_rtc_set_alarm()

We need to unlock if time is more than U32_MAX.

Fixes 83c880f79e88 ("rtc: add mxc driver for i.MX53 SRTC")
drivers/rtc/rtc-mxc_v2.c +3 -1
index 9e14efb990b2..90c9ab68688f 100644
@@ -243,12 +243,14 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
 	const time64_t time = rtc_tm_to_time64(&alrm->time);
 	struct mxc_rtc_data *pdata = dev_get_drvdata(dev);
-	int ret = mxc_rtc_lock(pdata);
+	int ret;
 
+	ret = mxc_rtc_lock(pdata);
 	if (ret)
 		return ret;
 
 	if (time > U32_MAX) {
+		mxc_rtc_unlock(pdata);
 		dev_err(dev, "Hopefully I am out of service by then :-(\n");
 		return -EINVAL;
 	}
#1 lore raw
Quoted 5 lines

From: Dan Carpenter [mailto:[email protected]]
Sent: Mittwoch, 14. März 2018 08:37

We need to unlock if time is more than U32_MAX.

you are right, that's a bug.
But I would move the mxc_rtc_lock() entirely behind the (time > U32_MAX) check. IMHO that would make the code even cleaner. sorry for broken patch:

Quoted 6 lines
      const time64_t time = rtc_tm_to_time64(&alrm->time);
      struct mxc_rtc_data *pdata = dev_get_drvdata(dev);
drivers/rtc/rtc-mxc_v2.c +1 -3
-      int ret = mxc_rtc_lock(pdata);
+      int ret;
-
-      if (ret)

drivers/rtc/rtc-mxc_v2.c static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)

Quoted 10 lines
drivers/rtc/rtc-mxc_v2.c +4 -1
-              return ret;
 
      if (time > U32_MAX) {
              dev_err(dev, "Hopefully I am out of service by then :-(\n");
              return -EINVAL;
      }
+
+      ret = mxc_rtc_lock(pdata);
+      if (ret)
+              return ret;

---
Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff Registered office: Verl, Germany | Register court: Guetersloh HRA 7075

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 7 lines · Patrick Brünn
Quoted 5 lines

From: Dan Carpenter [mailto:[email protected]]
Sent: Mittwoch, 14. März 2018 08:37

We need to unlock if time is more than U32_MAX.

you are right, that's a bug.
But I would move the mxc_rtc_lock() entirely behind the (time > U32_MAX) check.

Yes, of course. I will resend.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html