linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] rtc: test: convert to devm_rtc_allocate_device
@ 2018-06-05 21:09 Alexandre Belloni
  2018-06-05 21:09 ` [PATCH 2/3] rtc: test: remove alarm support from the first device Alexandre Belloni
  2018-06-05 21:09 ` [PATCH 3/3] rtc: ensure rtc_set_alarm fails when alarms are not supported Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandre Belloni @ 2018-06-05 21:09 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

This allows further improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 70d4ab1d2769..6a6bc1f2a14d 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -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 = {
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/3] rtc: test: remove alarm support from the first device
  2018-06-05 21:09 [PATCH 1/3] rtc: test: convert to devm_rtc_allocate_device Alexandre Belloni
@ 2018-06-05 21:09 ` Alexandre Belloni
  2018-06-05 21:09 ` [PATCH 3/3] rtc: ensure rtc_set_alarm fails when alarms are not supported Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2018-06-05 21:09 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

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

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-test.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 6a6bc1f2a14d..9b7ef6f63251 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -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;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 3/3] rtc: ensure rtc_set_alarm fails when alarms are not supported
  2018-06-05 21:09 [PATCH 1/3] rtc: test: convert to devm_rtc_allocate_device Alexandre Belloni
  2018-06-05 21:09 ` [PATCH 2/3] rtc: test: remove alarm support from the first device Alexandre Belloni
@ 2018-06-05 21:09 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2018-06-05 21:09 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, 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.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/interface.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index ffcfe6319466..7cae46c6b9bf 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -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;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-05 21:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-05 21:09 [PATCH 1/3] rtc: test: convert to devm_rtc_allocate_device Alexandre Belloni
2018-06-05 21:09 ` [PATCH 2/3] rtc: test: remove alarm support from the first device Alexandre Belloni
2018-06-05 21:09 ` [PATCH 3/3] rtc: ensure rtc_set_alarm fails when alarms are not supported Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).