Skip to content

Commit 7dfaa7b

Browse files
arndbdavem330
authored andcommitted
bnxt: fix bnxt_hwrm_fw_set_time for y2038
On 32-bit architectures, rtc_time_to_tm() returns incorrect results in 2038 or later, and do_gettimeofday() is broken for the same reason. This changes the code to use ktime_get_real_seconds() and time64_to_tm() instead, both of them are 2038-safe, and we can also get rid of the CONFIG_RTC_LIB dependency that way. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 96c623e commit 7dfaa7b

File tree

1 file changed

+3
-8
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+3
-8
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,16 +4915,14 @@ static int bnxt_hwrm_ver_get(struct bnxt *bp)
49154915

49164916
int bnxt_hwrm_fw_set_time(struct bnxt *bp)
49174917
{
4918-
#if IS_ENABLED(CONFIG_RTC_LIB)
49194918
struct hwrm_fw_set_time_input req = {0};
4920-
struct rtc_time tm;
4921-
struct timeval tv;
4919+
struct tm tm;
4920+
time64_t now = ktime_get_real_seconds();
49224921

49234922
if (bp->hwrm_spec_code < 0x10400)
49244923
return -EOPNOTSUPP;
49254924

4926-
do_gettimeofday(&tv);
4927-
rtc_time_to_tm(tv.tv_sec, &tm);
4925+
time64_to_tm(now, 0, &tm);
49284926
bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
49294927
req.year = cpu_to_le16(1900 + tm.tm_year);
49304928
req.month = 1 + tm.tm_mon;
@@ -4933,9 +4931,6 @@ int bnxt_hwrm_fw_set_time(struct bnxt *bp)
49334931
req.minute = tm.tm_min;
49344932
req.second = tm.tm_sec;
49354933
return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4936-
#else
4937-
return -EOPNOTSUPP;
4938-
#endif
49394934
}
49404935

49414936
static int bnxt_hwrm_port_qstats(struct bnxt *bp)

0 commit comments

Comments
 (0)