public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/rtc/interface.c: check the error after __rtc_read_time()
@ 2014-07-04  1:22 Hyogi Gim
  2014-07-30 17:44 ` John Stultz
  0 siblings, 1 reply; 5+ messages in thread
From: Hyogi Gim @ 2014-07-04  1:22 UTC (permalink / raw)
  To: Alessandro Zummo, John Stultz; +Cc: rtc-linux, linux-kernel, Hyogi Gim

In __rtc_set_alarm(), the error after __rtc_read_time() is not checked.
If rtc device fail to read time, we cannot guarantee the following process.

Add the verification code for returned __rtc_read_time() error.

Signed-off-by: Hyogi Gim <hyogi.gim@lge.com>
---
 drivers/rtc/interface.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 5813fa5..5b2717f 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -348,6 +348,8 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 
 	/* Make sure we're not setting alarms in the past */
 	err = __rtc_read_time(rtc, &tm);
+	if (err)
+		return err;
 	rtc_tm_to_time(&tm, &now);
 	if (scheduled <= now)
 		return -ETIME;
-- 
1.8.3.2


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

* Re: [PATCH] drivers/rtc/interface.c: check the error after __rtc_read_time()
  2014-07-04  1:22 Hyogi Gim
@ 2014-07-30 17:44 ` John Stultz
  0 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2014-07-30 17:44 UTC (permalink / raw)
  To: Hyogi Gim; +Cc: Alessandro Zummo, rtc-linux@googlegroups.com, lkml

On Thu, Jul 3, 2014 at 6:22 PM, Hyogi Gim <hyogi.gim@lge.com> wrote:
> In __rtc_set_alarm(), the error after __rtc_read_time() is not checked.
> If rtc device fail to read time, we cannot guarantee the following process.
>
> Add the verification code for returned __rtc_read_time() error.
>
> Signed-off-by: Hyogi Gim <hyogi.gim@lge.com>

Thanks for sending this in. Sorry I didn't get to it earlier. I've got
it queued for testing and hopefully will make it for 3.17 (but I may
be cutting it close).

thanks
-john

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

* [PATCH] drivers/rtc/interface.c: check the error after __rtc_read_time()
@ 2014-12-17  3:15 Hyogi Gim
  2014-12-17 21:51 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Hyogi Gim @ 2014-12-17  3:15 UTC (permalink / raw)
  To: a.zummo, akpm; +Cc: rtc-linux, linux-kernel

Add the verification code for returned __rtc_read_time() error in
rtc_update_irq_enable() and rtc_timer_do_work().

Signed-off-by: Hyogi Gim <hyogi.gim@lge.com>
---
 drivers/rtc/interface.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 45bfc28ee..fa1f119 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -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);
 }
-- 
1.8.3.2


-- 
Hyogi


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

* Re: [PATCH] drivers/rtc/interface.c: check the error after __rtc_read_time()
  2014-12-17  3:15 [PATCH] drivers/rtc/interface.c: check the error after __rtc_read_time() Hyogi Gim
@ 2014-12-17 21:51 ` Andrew Morton
  2014-12-22  2:43   ` Hyogi Gim
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2014-12-17 21:51 UTC (permalink / raw)
  To: Hyogi Gim; +Cc: a.zummo, rtc-linux, linux-kernel

On Wed, 17 Dec 2014 12:15:24 +0900 Hyogi Gim <hyogi.gim@lge.com> wrote:

> Add the verification code for returned __rtc_read_time() error in
> rtc_update_irq_enable() and rtc_timer_do_work().
> 
> ...
L
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -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);

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.


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

* Re: [PATCH] drivers/rtc/interface.c: check the error after __rtc_read_time()
  2014-12-17 21:51 ` Andrew Morton
@ 2014-12-22  2:43   ` Hyogi Gim
  0 siblings, 0 replies; 5+ messages in thread
From: Hyogi Gim @ 2014-12-22  2:43 UTC (permalink / raw)
  To: Andrew Morton; +Cc: a.zummo, rtc-linux, linux-kernel

On Wed, Dec 17, 2014 at 01:51:50PM -0800, Andrew Morton wrote:
> On Wed, 17 Dec 2014 12:15:24 +0900 Hyogi Gim <hyogi.gim@lge.com> wrote:
> 
> > Add the verification code for returned __rtc_read_time() error in
> > rtc_update_irq_enable() and rtc_timer_do_work().
> > 
> > ...
> L
> > --- a/drivers/rtc/interface.c
> > +++ b/drivers/rtc/interface.c
> > @@ -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);
> 
> 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.
> 

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().


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

end of thread, other threads:[~2014-12-22  2:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-17  3:15 [PATCH] drivers/rtc/interface.c: check the error after __rtc_read_time() Hyogi Gim
2014-12-17 21:51 ` Andrew Morton
2014-12-22  2:43   ` Hyogi Gim
  -- strict thread matches above, loose matches on Subject: below --
2014-07-04  1:22 Hyogi Gim
2014-07-30 17:44 ` John Stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox