Skip to contentSkip to conversation

rtc: sd3078: Fix BCD encoding of the month

PATCH New Thorsten Blum 2 participants 2 messages Nov 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: sd3078: Fix BCD encoding of the month

The SD3078 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 1d67a232105b ("rtc: sd3078: new driver.")
---
 drivers/rtc/rtc-sd3078.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-sd3078.c +1 -1
index 2c61f0e204a4..7ceb6f866492 100644
@@ -119,7 +119,7 @@ static int sd3078_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	rtc_data[SD3078_REG_HR] = bin2bcd(tm->tm_hour) | 0x80;
 	rtc_data[SD3078_REG_DM] = bin2bcd(tm->tm_mday);
 	rtc_data[SD3078_REG_DW] = tm->tm_wday & 0x07;
-	rtc_data[SD3078_REG_MO] = bin2bcd(tm->tm_mon) + 1;
+	rtc_data[SD3078_REG_MO] = bin2bcd(tm->tm_mon + 1);
 	rtc_data[SD3078_REG_YR] = bin2bcd(tm->tm_year - 100);
 
 #if WRITE_PROTECT_EN
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

The SD3078 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 1d67a232105b ("rtc: sd3078: new driver.")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1