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

driver/rtc/class.c: check the error after rtc_read_time()

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 <hyogi.gim@lge.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Hyogi Gim and committed by
Linus Torvalds
e1d60093 796b7abb

+14 -2
+14 -2
drivers/rtc/class.c
··· 53 53 struct rtc_device *rtc = to_rtc_device(dev); 54 54 struct rtc_time tm; 55 55 struct timespec delta, delta_delta; 56 + int err; 56 57 57 58 if (has_persistent_clock()) 58 59 return 0; ··· 62 61 return 0; 63 62 64 63 /* snapshot the current RTC and system time at suspend*/ 65 - rtc_read_time(rtc, &tm); 64 + err = rtc_read_time(rtc, &tm); 65 + if (err < 0) { 66 + pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); 67 + return 0; 68 + } 69 + 66 70 getnstimeofday(&old_system); 67 71 rtc_tm_to_time(&tm, &old_rtc.tv_sec); 68 72 ··· 100 94 struct rtc_time tm; 101 95 struct timespec new_system, new_rtc; 102 96 struct timespec sleep_time; 97 + int err; 103 98 104 99 if (has_persistent_clock()) 105 100 return 0; ··· 111 104 112 105 /* snapshot the current rtc and system time at resume */ 113 106 getnstimeofday(&new_system); 114 - rtc_read_time(rtc, &tm); 107 + err = rtc_read_time(rtc, &tm); 108 + if (err < 0) { 109 + pr_debug("%s: fail to read rtc time\n", dev_name(&rtc->dev)); 110 + return 0; 111 + } 112 + 115 113 if (rtc_valid_tm(&tm) != 0) { 116 114 pr_debug("%s: bogus resume time\n", dev_name(&rtc->dev)); 117 115 return 0;