diff mbox

[v3] rtc: pcf8563 fix: return -EINVAL if we read an invalid time.

Message ID 1432795725-8350-1-git-send-email-jan.kardell@telliq.com
State Accepted
Headers show

Commit Message

Jan Kardell May 28, 2015, 6:48 a.m. UTC
Return -EINVAL if the voltage low bit is set to avoid getting a bogus
time at boot.
There was a comment stating that util-linux hwclock refuses to set a
new time if we return an error code on read, but at least the current
version do set the time as expected. Remove the comment and the check
for valid time, and let the rtc core check it for us.

Changes in v2: Remove the test for invalid time. Change dev_err to
dev_info when voltage low is set.

Changes in v3: Use dev_err when voltage low is set.

Signed-off-by: Jan Kardell <jan.kardell@telliq.com>
---
 drivers/rtc/rtc-pcf8563.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Alexandre Belloni May 30, 2015, 9:56 p.m. UTC | #1
On 28/05/2015 at 08:48:45 +0200, Jan Kardell wrote :
> Return -EINVAL if the voltage low bit is set to avoid getting a bogus
> time at boot.
> There was a comment stating that util-linux hwclock refuses to set a
> new time if we return an error code on read, but at least the current
> version do set the time as expected. Remove the comment and the check
> for valid time, and let the rtc core check it for us.
> 
> Changes in v2: Remove the test for invalid time. Change dev_err to
> dev_info when voltage low is set.
> 
> Changes in v3: Use dev_err when voltage low is set.
> 
> Signed-off-by: Jan Kardell <jan.kardell@telliq.com>
> ---
>  drivers/rtc/rtc-pcf8563.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)

Applied, thanks.
diff mbox

Patch

diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 0ba7e59..229426d 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -22,7 +22,7 @@ 
 #include <linux/of.h>
 #include <linux/err.h>
 
-#define DRV_VERSION "0.4.3"
+#define DRV_VERSION "0.4.4"
 
 #define PCF8563_REG_ST1		0x00 /* status */
 #define PCF8563_REG_ST2		0x01
@@ -202,8 +202,9 @@  static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
 
 	if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) {
 		pcf8563->voltage_low = 1;
-		dev_info(&client->dev,
+		dev_err(&client->dev,
 			"low voltage detected, date/time is not reliable.\n");
+		return -EINVAL;
 	}
 
 	dev_dbg(&client->dev,
@@ -234,12 +235,6 @@  static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
 		tm->tm_sec, tm->tm_min, tm->tm_hour,
 		tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
 
-	/* the clock can give out invalid datetime, but we cannot return
-	 * -EINVAL otherwise hwclock will refuse to set the time on bootup.
-	 */
-	if (rtc_valid_tm(tm) < 0)
-		dev_err(&client->dev, "retrieved date/time is not valid.\n");
-
 	return 0;
 }