Skip to contentSkip to conversation

rtc: test: convert to devm_rtc_allocate_device

PATCH New Alexandre Belloni 1 participant 3 messages Jun 5, 2018 Real time clock (RTC)

lore
Share & tools
lore

Alexandre Belloni

author maintainer
#0 lore raw

PATCH 1/3 rtc: test: convert to devm_rtc_allocate_device

This allows further improvement of the driver.

---
 drivers/rtc/rtc-test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/rtc/rtc-test.c +4 -3
index 70d4ab1d2769..6a6bc1f2a14d 100644
@@ -120,15 +120,16 @@ static int test_probe(struct platform_device *plat_dev)
 
 	platform_set_drvdata(plat_dev, rtd);
 
-	rtd->rtc = devm_rtc_device_register(&plat_dev->dev, "test",
-					    &test_rtc_ops, THIS_MODULE);
+	rtd->rtc = devm_rtc_allocate_device(&plat_dev->dev);
 	if (IS_ERR(rtd->rtc))
 		return PTR_ERR(rtd->rtc);
 
+	rtd->rtc->ops = &test_rtc_ops;
+
 	timer_setup(&rtd->alarm, test_rtc_alarm_handler, 0);
 	rtd->alarm.expires = 0;
 
-	return 0;
+	return rtc_register_device(rtd->rtc);
 }
 
 static struct platform_driver test_driver = {
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 2/3 rtc: test: remove alarm support from the first device

To test for issues with RTCs that don't provide an alarm, remove alarm support from the first test RTC device.

---
 drivers/rtc/rtc-test.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/rtc/rtc-test.c +13 -1
index 6a6bc1f2a14d..9b7ef6f63251 100644
@@ -95,6 +95,12 @@ static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
 	return 0;
 }
 
+static const struct rtc_class_ops test_rtc_ops_noalm = {
+	.read_time = test_rtc_read_time,
+	.set_mmss64 = test_rtc_set_mmss64,
+	.alarm_irq_enable = test_rtc_alarm_irq_enable,
+};
+
 static const struct rtc_class_ops test_rtc_ops = {
 	.read_time = test_rtc_read_time,
 	.read_alarm = test_rtc_read_alarm,
@@ -124,7 +130,13 @@ static int test_probe(struct platform_device *plat_dev)
 	if (IS_ERR(rtd->rtc))
 		return PTR_ERR(rtd->rtc);
 
-	rtd->rtc->ops = &test_rtc_ops;
+	switch (plat_dev->id) {
+	case 0:
+		rtd->rtc->ops = &test_rtc_ops_noalm;
+		break;
+	default:
+		rtd->rtc->ops = &test_rtc_ops;
+	}
 
 	timer_setup(&rtd->alarm, test_rtc_alarm_handler, 0);
 	rtd->alarm.expires = 0;
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH 3/3 rtc: ensure rtc_set_alarm fails when alarms are not supported

In reply to Alexandre Belloni

When using RTC_ALM_SET or RTC_WKALM_SET with rtc_wkalrm.enabled not set, rtc_timer_enqueue() is not called and rtc_set_alarm() may succeed but the subsequent RTC_AIE_ON ioctl will fail. RTC_ALM_READ would also fail in that case.

Ensure rtc_set_alarm() fails when alarms are not supported to avoid letting programs think the alarms are working for a particular RTC when they are not.

---
 drivers/rtc/interface.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/rtc/interface.c +5 -0
index ffcfe6319466..7cae46c6b9bf 100644
@@ -442,6 +442,11 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 {
 	int err;
 
+	if (!rtc->ops)
+		return -ENODEV;
+	else if (!rtc->ops->set_alarm)
+		return -EINVAL;
+
 	err = rtc_valid_tm(&alarm->time);
 	if (err != 0)
 		return err;
Signature · 1 line
2.17.1