Skip to content

Commit

Permalink
driver/rtc/class.c: check the error after rtc_read_time()
Browse files Browse the repository at this point in the history
In rtc_suspend() and rtc_resume(), 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 <[email protected]>
Cc: Alessandro Zummo <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Hyogi Gim authored and torvalds committed Aug 8, 2014
1 parent 796b7ab commit e1d6009
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions drivers/rtc/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static int rtc_suspend(struct device *dev)
struct rtc_device *rtc = to_rtc_device(dev);
struct rtc_time tm;
struct timespec delta, delta_delta;
int err;

if (has_persistent_clock())
return 0;
Expand All @@ -61,7 +62,12 @@ static int rtc_suspend(struct device *dev)
return 0;

/* snapshot the current RTC and system time at suspend*/
rtc_read_time(rtc, &tm);
err = rtc_read_time(rtc, &tm);
if (err < 0) {
pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev));
return 0;
}

getnstimeofday(&old_system);
rtc_tm_to_time(&tm, &old_rtc.tv_sec);

Expand Down Expand Up @@ -94,6 +100,7 @@ static int rtc_resume(struct device *dev)
struct rtc_time tm;
struct timespec new_system, new_rtc;
struct timespec sleep_time;
int err;

if (has_persistent_clock())
return 0;
Expand All @@ -104,7 +111,12 @@ static int rtc_resume(struct device *dev)

/* snapshot the current rtc and system time at resume */
getnstimeofday(&new_system);
rtc_read_time(rtc, &tm);
err = rtc_read_time(rtc, &tm);
if (err < 0) {
pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev));
return 0;
}

if (rtc_valid_tm(&tm) != 0) {
pr_debug("%s: bogus resume time\n", dev_name(&rtc->dev));
return 0;
Expand Down

0 comments on commit e1d6009

Please sign in to comment.