Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: rtc_update_irq_enable: rework UIE emulation

Now that the core is aware of whether alarms are available, it is possible
to decide whether UIE emulation is required before actually trying to set
the alarm.

This greatly simplifies rtc_update_irq_enable because there is now only one
error value to track and is not relying on the return value of
__rtc_set_alarm anymore.

Tested-by: Łukasz Stelmach <l.stelmach@samsung.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210418000023.995758-3-alexandre.belloni@bootlin.com

+10 -24
+10 -24
drivers/rtc/interface.c
··· 545 545 546 546 int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) 547 547 { 548 - int rc = 0, err; 548 + int err; 549 549 550 550 err = mutex_lock_interruptible(&rtc->ops_lock); 551 551 if (err) ··· 561 561 if (rtc->uie_rtctimer.enabled == enabled) 562 562 goto out; 563 563 564 - if (rtc->uie_unsupported) { 565 - err = -EINVAL; 566 - goto out; 564 + if (rtc->uie_unsupported || !test_bit(RTC_FEATURE_ALARM, rtc->features)) { 565 + mutex_unlock(&rtc->ops_lock); 566 + #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 567 + return rtc_dev_update_irq_enable_emul(rtc, enabled); 568 + #else 569 + return -EINVAL; 570 + #endif 567 571 } 568 572 569 573 if (enabled) { 570 574 struct rtc_time tm; 571 575 ktime_t now, onesec; 572 576 573 - rc = __rtc_read_time(rtc, &tm); 574 - if (rc) 577 + err = __rtc_read_time(rtc, &tm); 578 + if (err) 575 579 goto out; 576 580 onesec = ktime_set(1, 0); 577 581 now = rtc_tm_to_ktime(tm); ··· 589 585 out: 590 586 mutex_unlock(&rtc->ops_lock); 591 587 592 - /* 593 - * __rtc_read_time() failed, this probably means that the RTC time has 594 - * never been set or less probably there is a transient error on the 595 - * bus. In any case, avoid enabling emulation has this will fail when 596 - * reading the time too. 597 - */ 598 - if (rc) 599 - return rc; 600 - 601 - #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 602 - /* 603 - * Enable emulation if the driver returned -EINVAL to signal that it has 604 - * been configured without interrupts or they are not available at the 605 - * moment. 606 - */ 607 - if (err == -EINVAL) 608 - err = rtc_dev_update_irq_enable_emul(rtc, enabled); 609 - #endif 610 588 return err; 611 589 } 612 590 EXPORT_SYMBOL_GPL(rtc_update_irq_enable);