linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid
@ 2019-12-12 15:31 Paul Kocialkowski
  2019-12-12 15:31 ` [PATCH v2 2/2] rtc: hym8563: Read the valid flag directly instead of caching it Paul Kocialkowski
  2019-12-23 10:18 ` [PATCH v2 1/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid Alexandre Belloni
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Kocialkowski @ 2019-12-12 15:31 UTC (permalink / raw)
  To: linux-rtc, linux-kernel
  Cc: Alessandro Zummo, Alexandre Belloni, Paul Kocialkowski

The current code returns -EPERM when the voltage loss bit is set.
Since the bit indicates that the time value is not valid, return
-EINVAL instead, which is the appropriate error code for this
situation.

Fixes: dcaf03849352 ("rtc: add hym8563 rtc-driver")
Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
Changes since v1:
- Addded Fixes tag.

 drivers/rtc/rtc-hym8563.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c
index 443f6d05ce29..fb6d7967ec00 100644
--- a/drivers/rtc/rtc-hym8563.c
+++ b/drivers/rtc/rtc-hym8563.c
@@ -97,7 +97,7 @@ static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
 
 	if (!hym8563->valid) {
 		dev_warn(&client->dev, "no valid clock/calendar values available\n");
-		return -EPERM;
+		return -EINVAL;
 	}
 
 	ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf);
-- 
2.24.0


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

* [PATCH v2 2/2] rtc: hym8563: Read the valid flag directly instead of caching it
  2019-12-12 15:31 [PATCH v2 1/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid Paul Kocialkowski
@ 2019-12-12 15:31 ` Paul Kocialkowski
  2019-12-23 10:18   ` Alexandre Belloni
  2019-12-23 10:18 ` [PATCH v2 1/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid Alexandre Belloni
  1 sibling, 1 reply; 4+ messages in thread
From: Paul Kocialkowski @ 2019-12-12 15:31 UTC (permalink / raw)
  To: linux-rtc, linux-kernel
  Cc: Alessandro Zummo, Alexandre Belloni, Paul Kocialkowski

The RTC has a valid bit in the seconds register that indicates whether
power was lost since the pevious time set. This bit is currently read
once at probe time, cached and updated with set_time.

Howeever, caching the bit may prevent detecting power loss at runtime
(which can happen if the RTC's supply is distinct from the the platform's).

Writing the seconds register when setting time will clear the bit,
so there should be no downside in reading the bit directly instead of
caching it.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
Changes since v1:
- Removed hym8563 unused variables;
- Checked buf[0] for VL flag instead of ret;
- Reorded patches.

 drivers/rtc/rtc-hym8563.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c
index fb6d7967ec00..0fb79c4afb46 100644
--- a/drivers/rtc/rtc-hym8563.c
+++ b/drivers/rtc/rtc-hym8563.c
@@ -78,7 +78,6 @@
 struct hym8563 {
 	struct i2c_client	*client;
 	struct rtc_device	*rtc;
-	bool			valid;
 #ifdef CONFIG_COMMON_CLK
 	struct clk_hw		clkout_hw;
 #endif
@@ -91,19 +90,19 @@ struct hym8563 {
 static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
 	struct i2c_client *client = to_i2c_client(dev);
-	struct hym8563 *hym8563 = i2c_get_clientdata(client);
 	u8 buf[7];
 	int ret;
 
-	if (!hym8563->valid) {
-		dev_warn(&client->dev, "no valid clock/calendar values available\n");
-		return -EINVAL;
-	}
-
 	ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf);
 	if (ret < 0)
 		return ret;
 
+	if (buf[0] & HYM8563_SEC_VL) {
+		dev_warn(&client->dev,
+			 "no valid clock/calendar values available\n");
+		return -EINVAL;
+	}
+
 	tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK);
 	tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK);
 	tm->tm_hour = bcd2bin(buf[2] & HYM8563_HOUR_MASK);
@@ -118,7 +117,6 @@ static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
 static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
 	struct i2c_client *client = to_i2c_client(dev);
-	struct hym8563 *hym8563 = i2c_get_clientdata(client);
 	u8 buf[7];
 	int ret;
 
@@ -157,8 +155,6 @@ static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	if (ret < 0)
 		return ret;
 
-	hym8563->valid = true;
-
 	return 0;
 }
 
@@ -556,9 +552,8 @@ static int hym8563_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	hym8563->valid = !(ret & HYM8563_SEC_VL);
 	dev_dbg(&client->dev, "rtc information is %s\n",
-		hym8563->valid ? "valid" : "invalid");
+		(ret & HYM8563_SEC_VL) ? "invalid" : "valid");
 
 	hym8563->rtc = devm_rtc_device_register(&client->dev, client->name,
 						&hym8563_rtc_ops, THIS_MODULE);
-- 
2.24.0


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

* Re: [PATCH v2 1/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid
  2019-12-12 15:31 [PATCH v2 1/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid Paul Kocialkowski
  2019-12-12 15:31 ` [PATCH v2 2/2] rtc: hym8563: Read the valid flag directly instead of caching it Paul Kocialkowski
@ 2019-12-23 10:18 ` Alexandre Belloni
  1 sibling, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2019-12-23 10:18 UTC (permalink / raw)
  To: Paul Kocialkowski; +Cc: linux-rtc, linux-kernel, Alessandro Zummo

On 12/12/2019 16:31:10+0100, Paul Kocialkowski wrote:
> The current code returns -EPERM when the voltage loss bit is set.
> Since the bit indicates that the time value is not valid, return
> -EINVAL instead, which is the appropriate error code for this
> situation.
> 
> Fixes: dcaf03849352 ("rtc: add hym8563 rtc-driver")
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
> Changes since v1:
> - Addded Fixes tag.
> 
>  drivers/rtc/rtc-hym8563.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH v2 2/2] rtc: hym8563: Read the valid flag directly instead of caching it
  2019-12-12 15:31 ` [PATCH v2 2/2] rtc: hym8563: Read the valid flag directly instead of caching it Paul Kocialkowski
@ 2019-12-23 10:18   ` Alexandre Belloni
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2019-12-23 10:18 UTC (permalink / raw)
  To: Paul Kocialkowski; +Cc: linux-rtc, linux-kernel, Alessandro Zummo

On 12/12/2019 16:31:11+0100, Paul Kocialkowski wrote:
> The RTC has a valid bit in the seconds register that indicates whether
> power was lost since the pevious time set. This bit is currently read
> once at probe time, cached and updated with set_time.
> 
> Howeever, caching the bit may prevent detecting power loss at runtime
> (which can happen if the RTC's supply is distinct from the the platform's).
> 
> Writing the seconds register when setting time will clear the bit,
> so there should be no downside in reading the bit directly instead of
> caching it.
> 
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
> Changes since v1:
> - Removed hym8563 unused variables;
> - Checked buf[0] for VL flag instead of ret;
> - Reorded patches.
> 
>  drivers/rtc/rtc-hym8563.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2019-12-23 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-12 15:31 [PATCH v2 1/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid Paul Kocialkowski
2019-12-12 15:31 ` [PATCH v2 2/2] rtc: hym8563: Read the valid flag directly instead of caching it Paul Kocialkowski
2019-12-23 10:18   ` Alexandre Belloni
2019-12-23 10:18 ` [PATCH v2 1/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).