From patchwork Tue Nov 7 10:46:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10046285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A567E60360 for ; Tue, 7 Nov 2017 10:46:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86A0D2A0B2 for ; Tue, 7 Nov 2017 10:46:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78E712A0BA; Tue, 7 Nov 2017 10:46:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38C1C29C91 for ; Tue, 7 Nov 2017 10:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757209AbdKGKqa (ORCPT ); Tue, 7 Nov 2017 05:46:30 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:56118 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753167AbdKGKq1 (ORCPT ); Tue, 7 Nov 2017 05:46:27 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lvg76-1fJHnH1yfc-017TSU; Tue, 07 Nov 2017 11:46:15 +0100 From: Arnd Bergmann To: Adaptec OEM Raid Solutions , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Arnd Bergmann , David Carroll , Raghava Aditya Renukunta , Johannes Thumshirn , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] aacraid: use timespec64 instead of timeval Date: Tue, 7 Nov 2017 11:46:05 +0100 Message-Id: <20171107104613.3183755-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:sAayuAHt9+YK28KmlVcFktRH9GBZadDyLfkSQxL+q9ez+nYBIkO F73aF+YEbD6mQPH44EDczZU4gQH8jhEDT/tx3esMzeTZZmC2XnQyaie2p5EU9tUo29CR5X6 XNVy6j7rgDnjppvlxMnTpGvdDO4NxrH3x2aKrNo5njv64PbaUkl9eWtWW9/gKLs4bC6NGJC c3CBemf7rdaUsbyJO2DGA== X-UI-Out-Filterresults: notjunk:1; V01:K0:Tiofv0YezQY=:vKf0XpjWmkEJt0NpGXh9Us jMVYGrdCHNMk8eilpFHFUwGkqSZfZ6oqcl5HuMCKQEnD243mTwGZfbHp1CRIB6R2WVkJajqqk 5uoq4RXEc/6KQIFyMmaA6cu7XtDS3tSlXlnSFRrW015ppdLqcpBDX+BsZrQYKfb/9lOM6nZZZ 0xZYy7YUfI57xfTtrjCpaujWMmTizLoBtyIM7dvaYiW/KYqI5YDyAnIsgob4+YVcC3EbDyaJo /24fQmk47GWA6IApblh7WBP5wytpv2rryYUnpK8fQPO4rWoOtKn8MdEPOYhwRNhgMu7w8Su15 POAEl+u1/rDU04dhJWGKx5+7l5j8a6wE2NKJcbH3mXLrDmxcl2QYjhApzIth+jDx5nrW8ccK8 kiVb/crk/70xybMgp5I8v+SdpdwsYK3VrUxJpWFG1vuxwBrkaSJ4bIVxFrRZsVNYwFsing20U 0xqX9dP45OIrUSpZDm9EfQypwnx6OKnV/AP/QPn/+8Ok0khPmWPtncBW52RtCBWtopJG7kJ1Y pRJlQZGbfQSLiXYphmPmgbaTb4OEXWzrpdER+/kUAR5delihfRqv+7Ubl7nh1PEOzaZR8ssvW /PxqIdNqsjeeCWtEGdhmNvIl1dr1o6nySVsa6722O+HpPFHDxZGxU756F8xHEvkYWyBUxt6Oh eJP6gndvRe7LOdHf/uCJOPzWdnf8inSqrDRxRlG4KcreG79EP4gAMswgIxd2AOGinAtSZEZF9 J9xLIWPqh+wmqO1aPp9DMLScq+HoEdIOmCb8KQ== Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP aacraid passes the current time to the firmware in one of two ways, either as year/month/day/... or as 32-bit unsigned seconds. The first one is broken on 32-bit architectures as it cannot go past year 2038. Using timespec64 here makes it behave properly on both 32-bit and 64-bit architectures, and avoids relying on signed integer overflow to pass times into the second interface. The interface used in aac_send_hosttime() however is still problematic in year 2106 when 32-bit seconds overflow. Hopefully we don't have to worry about aacraid by that time. Signed-off-by: Arnd Bergmann Reviewed-by: Dave Carroll --- drivers/scsi/aacraid/commsup.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c index dfe8e70f8d99..525a652dab48 100644 --- a/drivers/scsi/aacraid/commsup.c +++ b/drivers/scsi/aacraid/commsup.c @@ -2383,19 +2383,19 @@ static int aac_send_wellness_command(struct aac_dev *dev, char *wellness_str, goto out; } -int aac_send_safw_hostttime(struct aac_dev *dev, struct timeval *now) +int aac_send_safw_hostttime(struct aac_dev *dev, struct timespec64 *now) { struct tm cur_tm; char wellness_str[] = "TD\010\0\0\0\0\0\0\0\0\0DW\0\0ZZ"; u32 datasize = sizeof(wellness_str); - unsigned long local_time; + time64_t local_time; int ret = -ENODEV; if (!dev->sa_firmware) goto out; - local_time = (u32)(now->tv_sec - (sys_tz.tz_minuteswest * 60)); - time_to_tm(local_time, 0, &cur_tm); + local_time = (now->tv_sec - (sys_tz.tz_minuteswest * 60)); + time64_to_tm(local_time, 0, &cur_tm); cur_tm.tm_mon += 1; cur_tm.tm_year += 1900; wellness_str[8] = bin2bcd(cur_tm.tm_hour); @@ -2412,7 +2412,7 @@ int aac_send_safw_hostttime(struct aac_dev *dev, struct timeval *now) return ret; } -int aac_send_hosttime(struct aac_dev *dev, struct timeval *now) +int aac_send_hosttime(struct aac_dev *dev, struct timespec64 *now) { int ret = -ENOMEM; struct fib *fibptr; @@ -2424,7 +2424,7 @@ int aac_send_hosttime(struct aac_dev *dev, struct timeval *now) aac_fib_init(fibptr); info = (__le32 *)fib_data(fibptr); - *info = cpu_to_le32(now->tv_sec); + *info = cpu_to_le32(now->tv_sec); /* overflow in y2106 */ ret = aac_fib_send(SendHostTime, fibptr, sizeof(*info), FsaNormal, 1, 1, NULL, NULL); @@ -2496,7 +2496,7 @@ int aac_command_thread(void *data) } if (!time_before(next_check_jiffies,next_jiffies) && ((difference = next_jiffies - jiffies) <= 0)) { - struct timeval now; + struct timespec64 now; int ret; /* Don't even try to talk to adapter if its sick */ @@ -2506,15 +2506,15 @@ int aac_command_thread(void *data) next_check_jiffies = jiffies + ((long)(unsigned)check_interval) * HZ; - do_gettimeofday(&now); + ktime_get_real_ts64(&now); /* Synchronize our watches */ - if (((1000000 - (1000000 / HZ)) > now.tv_usec) - && (now.tv_usec > (1000000 / HZ))) - difference = (((1000000 - now.tv_usec) * HZ) - + 500000) / 1000000; + if (((NSEC_PER_SEC - (NSEC_PER_SEC / HZ)) > now.tv_nsec) + && (now.tv_nsec > (NSEC_PER_SEC / HZ))) + difference = (((NSEC_PER_SEC - now.tv_nsec) * HZ) + + NSEC_PER_SEC / 2) / NSEC_PER_SEC; else { - if (now.tv_usec > 500000) + if (now.tv_nsec > NSEC_PER_SEC / 2) ++now.tv_sec; if (dev->sa_firmware)