drivers/rtc/interface.c: check the error after __rtc_read_time()
PATCH 1/1 drivers/rtc/interface.c: check the error after __rtc_read_time()
Add the verification code for returned __rtc_read_time() error in rtc_update_irq_enable() and rtc_timer_do_work().
--- drivers/rtc/interface.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/rtc/interface.c +10 -3
@@ -489,7 +489,10 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)struct rtc_time tm;ktime_t now, onesec; -__rtc_read_time (rtc, &tm); + err =__rtc_read_time (rtc, &tm); +if (err <0 ) + goto out; + onesec =ktime_set (1 ,0 ); now =rtc_tm_to_ktime (tm); rtc->uie_rtctimer.node.expires =ktime_add (now, onesec);
@@ -867,13 +870,17 @@ void rtc_timer_do_work(struct work_struct *work)struct timerqueue_node *next;ktime_t now;struct rtc_time tm; +int err =0 ;struct rtc_device *rtc = container_of(work, struct rtc_device, irqwork);mutex_lock (&rtc->ops_lock); again: -__rtc_read_time (rtc, &tm); + err =__rtc_read_time (rtc, &tm); +if (err <0 ) + goto out; + now =rtc_tm_to_ktime (tm);while ((next =timerqueue_getnext (&rtc->timerqueue))) {if (next->expires.tv64 > now.tv64)
@@ -898,7 +905,6 @@ again:/* Set next alarm */ if (next) {struct rtc_wkalrm alarm; -int err;int retry =3 ; alarm.time =rtc_ktime_to_tm (next->expires);
@@ -920,6 +926,7 @@ reprogram: }else rtc_alarm_disable (rtc); +out:pm_relax (rtc->dev.parent);mutex_unlock (&rtc->ops_lock); }
Signature · 5 lines
1.8.3.2 -- Hyogi
Quoted 4 lines · On Wed, 17 Dec 2014 12:15:24 +0900 Hyogi Gim <[email protected]> wrote:
Add the verification code for returned
__rtc_read_time()error inrtc_update_irq_enable()andrtc_timer_do_work()....
L
Quoted 4 lines
drivers/rtc/interface.c +0
-0@@ -489,7 +489,10 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)struct rtc_time tm;
drivers/rtc/interface.c int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) · line 498
Quoted 10 lines
drivers/rtc/interface.c +4
-1ktime_t now, onesec; -__rtc_read_time (rtc, &tm); + err =__rtc_read_time (rtc, &tm); +if (err <0 ) + goto out; + onesec =ktime_set (1 ,0 ); now =rtc_tm_to_ktime (tm); rtc->uie_rtctimer.node.expires =ktime_add (now, onesec);
I'm not sure about this part. If __rtc_read_time() returns -EINVAL (due to !rtc->ops->read_time) then rtc_update_irq_enable() will go and call rtc_dev_update_irq_enable_emul(), inappropriately.
On the other hand, if __rtc_read_time() returns -EINVAL because that's what rtc->ops->read_time() returned then perhaps rtc_update_irq_enable() *should* call rtc_dev_update_irq_enable_emul().
Messy.
Quoted 26 lines · Andrew Morton
Quoted 4 lines · On Wed, 17 Dec 2014 12:15:24 +0900 Hyogi Gim <[email protected]> wrote:
Add the verification code for returned
__rtc_read_time()error inrtc_update_irq_enable()andrtc_timer_do_work()....
L
Quoted 4 lines
drivers/rtc/interface.c +0
-0@@ -489,7 +489,10 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)struct rtc_time tm;drivers/rtc/interface.c int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) · line 498
Quoted 10 lines
drivers/rtc/interface.c +4
-1ktime_t now, onesec; -__rtc_read_time (rtc, &tm); + err =__rtc_read_time (rtc, &tm); +if (err <0 ) + goto out; + onesec =ktime_set (1 ,0 ); now =rtc_tm_to_ktime (tm); rtc->uie_rtctimer.node.expires =ktime_add (now, onesec);I'm not sure about this part. If
__rtc_read_time()returns-EINVAL(due to !rtc->ops->read_time) thenrtc_update_irq_enable()will go and callrtc_dev_update_irq_enable_emul(), inappropriately.
Quoted 6 lines
On the other hand, if
__rtc_read_time()returns-EINVALbecause that's whatrtc->ops->read_time()returned then perhapsrtc_update_irq_enable()*should* callrtc_dev_update_irq_enable_emul().Messy.
As you said, if rtc driver has no read_time callback, rtc_read_time() is failed in rtc_dev_update_irq_enable_emul() anyway.
rtc_dev_update_irq_enable_emul()
|_ set_uie()
|_ rtc_read_time()
What I worried about the error from rtc->ops->read_time(). If rtc->ops->read_time() returns another type of error except -EINVAL, then rtc interface can't run rtc_dev_update_irq_enable_emul().
I think it needs to be changed that check to ensure error for rtc_dev_update_irq_enable_emul().