Skip to contentSkip to conversation

macintosh/smu: Fix BCD encoding of the RTC month

PATCH In review Thorsten Blum 2 participants 4 messages Nov 24 Linux for power macintosh

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 macintosh/smu: Fix BCD encoding of the RTC month

The SMU expects a one-based month encoded as BCD, while tm_mon is zero-based. Adding 1 after converting tm_mon to BCD incorrectly encodes October as 0x0a instead of 0x10.

Add 1 to tm_mon before converting it to BCD.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/macintosh/smu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/macintosh/smu.c +2 -2
index c463760710b6..fb93094ff608 100644
@@ -374,7 +374,7 @@ static inline void smu_fill_set_rtc_cmd(struct smu_cmd_buf *cmd_buf,
 	cmd_buf->data[3] = hex2bcd(time->tm_hour);
 	cmd_buf->data[4] = time->tm_wday;
 	cmd_buf->data[5] = hex2bcd(time->tm_mday);
-	cmd_buf->data[6] = hex2bcd(time->tm_mon) + 1;
+	cmd_buf->data[6] = hex2bcd(time->tm_mon + 1);
 	cmd_buf->data[7] = hex2bcd(time->tm_year - 100);
 }
 
@@ -421,7 +421,7 @@ int smu_set_rtc_time(struct rtc_time *time, int spinwait)
 			      hex2bcd(time->tm_hour),
 			      time->tm_wday,
 			      hex2bcd(time->tm_mday),
-			      hex2bcd(time->tm_mon) + 1,
+			      hex2bcd(time->tm_mon + 1),
 			      hex2bcd(time->tm_year - 100));
 	if (rc)
 		return rc;
Reviewed-by on v1 1/1
#1 lore raw

Le 24/11/2026 à 14:23, Thorsten Blum a écrit :

Quoted 8 lines

The SMU expects a one-based month encoded as BCD, while tm_mon is zero-based. Adding 1 after converting tm_mon to BCD incorrectly encodes October as 0x0a instead of 0x10.

Add 1 to tm_mon before converting it to BCD.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Quoted 26 lines
---
  drivers/macintosh/smu.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/macintosh/smu.c +2 -2
index c463760710b6..fb93094ff608 100644
@@ -374,7 +374,7 @@ static inline void smu_fill_set_rtc_cmd(struct smu_cmd_buf *cmd_buf,
  	cmd_buf->data[3] = hex2bcd(time->tm_hour);
  	cmd_buf->data[4] = time->tm_wday;
  	cmd_buf->data[5] = hex2bcd(time->tm_mday);
-	cmd_buf->data[6] = hex2bcd(time->tm_mon) + 1;
+	cmd_buf->data[6] = hex2bcd(time->tm_mon + 1);
  	cmd_buf->data[7] = hex2bcd(time->tm_year - 100);
  }
 
@@ -421,7 +421,7 @@ int smu_set_rtc_time(struct rtc_time *time, int spinwait)
  			      hex2bcd(time->tm_hour),
  			      time->tm_wday,
  			      hex2bcd(time->tm_mday),
-			      hex2bcd(time->tm_mon) + 1,
+			      hex2bcd(time->tm_mon + 1),
  			      hex2bcd(time->tm_year - 100));
  	if (rc)
  		return rc;
#2 lore raw

Le 24/11/2026 à 16:46, Christophe Leroy (CS GROUP) a écrit :

Quoted 10 lines

Le 24/11/2026 à 14:23, Thorsten Blum a écrit :

Quoted 7 lines

The SMU expects a one-based month encoded as BCD, while tm_mon is zero-based. Adding 1 after converting tm_mon to BCD incorrectly encodes October as 0x0a instead of 0x10.

Add 1 to tm_mon before converting it to BCD.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

The real origin is commit faa5ee3743ff ("[PATCH] ppc64: Add basic support for the SMU chip in iMac G5")

Found on repository https://github.com/mpe/linux-fullhistory.git

Quoted 32 lines
Quoted 1 line
Quoted 27 lines

---
  drivers/macintosh/smu.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/macintosh/smu.c +2 -2
index c463760710b6..fb93094ff608 100644
@@ -374,7 +374,7 @@ static inline void smu_fill_set_rtc_cmd(struct 
 smu_cmd_buf *cmd_buf,
       cmd_buf->data[3] = hex2bcd(time->tm_hour);
       cmd_buf->data[4] = time->tm_wday;
       cmd_buf->data[5] = hex2bcd(time->tm_mday);
-    cmd_buf->data[6] = hex2bcd(time->tm_mon) + 1;
+    cmd_buf->data[6] = hex2bcd(time->tm_mon + 1);
       cmd_buf->data[7] = hex2bcd(time->tm_year - 100);
   }
@@ -421,7 +421,7 @@ int smu_set_rtc_time(struct rtc_time *time, int 
 spinwait)
                     hex2bcd(time->tm_hour),
                     time->tm_wday,
                     hex2bcd(time->tm_mday),
-                  hex2bcd(time->tm_mon) + 1,
+                  hex2bcd(time->tm_mon + 1),
                     hex2bcd(time->tm_year - 100));
       if (rc)

          return rc;

#3 lore raw
Quoted 6 lines · Christophe Leroy (CS GROUP)

Le 24/11/2026 à 16:46, Christophe Leroy (CS GROUP) a écrit :

Quoted 5 lines

Le 24/11/2026 à 14:23, Thorsten Blum a écrit :

Quoted 4 lines

The SMU expects a one-based month encoded as BCD, while tm_mon is zero-based. Adding 1 after converting tm_mon to BCD incorrectly encodes October as 0x0a instead of 0x10.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Add 1 to tm_mon before converting it to BCD.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

The real origin is commit faa5ee3743ff ("[PATCH] ppc64: Add basic support for the SMU chip in iMac G5")

Found on repository https://github.com/mpe/linux-fullhistory.git

Thanks for the review and for digging this up.

IIRC, we keep the Fixes: tag pointing to the initial git commit rather than referencing a commit that predates the history, don't we?