Skip to contentSkip to conversation

rtc/r9701: avoid second call to the rtc_valid_tm

PATCH In review Devendra Naga 2 participants 3 messages Jun 21, 2012 – Jun 22, 2012 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc/r9701: avoid second call to the rtc_valid_tm

r9701_get_datetime will call the rtc_valid_tm and it returns the value returned by rtc_valid_tm, which anyway can be used in the if

so calling rtc_valid_tm is not required.

---

This change is compiled tested only using gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 on x86_64 (intel core i3).

 drivers/rtc/rtc-r9701.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/rtc/rtc-r9701.c +1 -2
index 33b6ba0..e6c34c0 100644
@@ -138,8 +138,7 @@ static int __devinit r9701_probe(struct spi_device *spi)
 	 * contain invalid values. If so, try to write a default date:
 	 * 2000/1/1 00:00:00
 	 */
-	r9701_get_datetime(&spi->dev, &dt);
-	if (rtc_valid_tm(&dt)) {
+	if (r9701_get_datetime(&spi->dev, &dt)) {
 		dev_info(&spi->dev, "trying to repair invalid date/time\n");
 		dt.tm_sec  = 0;
 		dt.tm_min  = 0;
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 19 lines · On Thu, 21 Jun 2012 12:34:40 +0530 Devendra Naga <[email protected]>…

r9701_get_datetime will call the rtc_valid_tm and it returns the value returned by rtc_valid_tm, which anyway can be used in the if

so calling rtc_valid_tm is not required.

---

This change is compiled tested only using gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 on x86_64 (intel core i3).

 drivers/rtc/rtc-r9701.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/rtc/rtc-r9701.c +0 -0
index 33b6ba0..e6c34c0 100644

drivers/rtc/rtc-r9701.c static int __devinit r9701_probe(struct spi_device *spi) · line 144

Quoted 9 lines
drivers/rtc/rtc-r9701.c +1 -2
@@ -138,8 +138,7 @@ static int __devinit r9701_probe(struct spi_device *spi)
 	 * contain invalid values. If so, try to write a default date:
 	 * 2000/1/1 00:00:00
 	 */
-	r9701_get_datetime(&spi->dev, &dt);
-	if (rtc_valid_tm(&dt)) {
+	if (r9701_get_datetime(&spi->dev, &dt)) {
 		dev_info(&spi->dev, "trying to repair invalid date/time\n");
 		dt.tm_sec  = 0;
 		dt.tm_min  = 0;

Looks OK.

I think the driver would be better if we were to do this:

From: Andrew Morton <[email protected]>
Subject: drivers/rtc/rtc-r9701.c: check that r9701_set_datetime() succeeded

When the driver detects that the clock time is invalid, it attempts to write a sane time into the hardware. We curently assume that everything is OK is those writes succeeded. But it is better to re-read the time from the hardware to ensure that the new settings got there OK.

Cc Devendra Naga <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Anatolij Gustschin <[email protected]>
Cc Andreas Dumberger <[email protected]>

---

 drivers/rtc/rtc-r9701.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/rtc-r9701.c renamed from drivers/rtc/rtc-r9701.c~a +2 -1
diff -puN drivers/rtc/rtc-r9701.c~a drivers/rtc/rtc-r9701.c
@@ -147,7 +147,8 @@ static int __devinit r9701_probe(struct 
 		dt.tm_mon  = 0;
 		dt.tm_year = 100;
 
-		if (r9701_set_datetime(&spi->dev, &dt)) {
+		if (r9701_set_datetime(&spi->dev, &dt) ||
+				r9701_get_datetime(&spi->dev, &dt)) {
 			dev_err(&spi->dev, "cannot repair RTC register\n");
 			return -ENODEV;
 		}

_

But I can't test this :(

#2 lore raw

Hi Andrew,

Thanks a lot for the reply. :-)

Quoted 29 lines · Andrew Morton

On Thu, 21 Jun 2012 12:34:40 +0530
Looks OK.

I think the driver would be better if we were to do this:

From: Andrew Morton <[email protected]>
Subject: drivers/rtc/rtc-r9701.c: check that r9701_set_datetime() succeeded

When the driver detects that the clock time is invalid, it attempts to write a sane time into the hardware.  We curently assume that everything is OK is those writes succeeded.  But it is better to re-read the time from the hardware to ensure that the new settings got there OK.

Cc Devendra Naga <[email protected]>
Cc Alessandro Zummo <[email protected]>
Cc Anatolij Gustschin <[email protected]>
Cc Andreas Dumberger <[email protected]>

---

 drivers/rtc/rtc-r9701.c |    3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)

diff -puN drivers/rtc/rtc-r9701.c~a drivers/rtc/rtc-r9701.c

drivers/rtc/rtc-r9701.c static int __devinit r9701_probe(struct · line 151

Quoted 6 lines
drivers/rtc/rtc-r9701.c renamed from drivers/rtc/rtc-r9701.c~a +2 -1
@@ -147,7 +147,8 @@ static int __devinit r9701_probe(struct
                dt.tm_mon  = 0;
                dt.tm_year = 100;
 
-               if (r9701_set_datetime(&spi->dev, &dt)) {
+               if (r9701_set_datetime(&spi->dev, &dt) ||
+                               r9701_get_datetime(&spi->dev, &dt)) {

Yeah, agreed, crosschecking whether we have a valid time set at the hardware by the r9701_set_datetime.

Quoted 7 lines
drivers/rtc/rtc-r9701.c renamed from drivers/rtc/rtc-r9701.c~a +0 -0
                        dev_err(&spi->dev, "cannot repair RTC register\n");
                        return -ENODEV;
                }

_

But I can't test this :(

I also dont have the RTC-j9701 hardware :(.

i was thinking of cases like setting / getting of time from ioctl. but there was no ioctl support inside the driver.

i am really a newbie in kernel, pardon me if i told anything wrong ...

Thanks,
Devendra.