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: 118149 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3814959qgn; Tue, 7 Nov 2017 02:46:34 -0800 (PST) X-Google-Smtp-Source: ABhQp+QvJJ1kiaYq6tXC8xTlBeZI75v+6md3oCAOGxo7ngo1Qg7ci1AjeXC5L66SLooP+IO17nvR X-Received: by 10.99.180.3 with SMTP id s3mr17798327pgf.174.1510051594474; Tue, 07 Nov 2017 02:46:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510051594; cv=none; d=google.com; s=arc-20160816; b=WJUiCARyRXUxmbb/hh+dkjpvnxoquUoUrffnUKJz5qI2LAS4CLvKbw9vqy0MeoQbVF k4Yum8QDb7pRdTnTbiCUFAZyjJyYlI2mAEcbC9ysOU/Pid88veIHZip9X43rPnzIM/Mh 0s9fvR2xDPr1XTH0tADI2MtIVLCJkXlrJWVOXw+yoETE1tDcQmY9CoHFjf6c29wvjNCA GvxjRYWWIzUL4wscCoY6PxrzC2Hj3PQrgKOTal9260yCKAMot9BcmWtH49GH8U/0/oyr 9FV8mDEUeG9jfCctMMQiZwDKJR+eWluvYDgXruC1N4PHxHlPsnA6GYRM2Lc508+lMUsL nxNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=RgjD+yVVpWHwKm0vt5CttnbHz56irIMB6Re70vdAd2k=; b=IFXDCXFcI9eZtnUv7MQ4dym1UZRRcDXJnLTQ+2y77QBnpXS06fncMdaVpFZmHfK8zB 9HHZdDU7G5493K8tgPWPn/XrUC9dz/yvuJydw0V4qsySU1Hg35EqVXF98ZjPujfbw9xd qVd1WeiGe6DmzTaTUEbyrHchf1gr9g4lBJ8/ZYKz6hM2EN9CpnHEIpzVQFsTSGLVXb/B ZCtlWEevE2/0Ry/G7RhbaeULZ7/0ifhtWxJpKOCoIbi3SbuyuieuzoMhtn5pTqpwUpno i1jL/RJb9vNVEFPp7Q4aaRto2q7yE8CgW3G3ZqJj3V0uGXsdPORKl82l72Mw0mZabL4c o28Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13si840175pgf.700.2017.11.07.02.46.33; Tue, 07 Nov 2017 02:46:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757330AbdKGKqb (ORCPT + 26 others); Tue, 7 Nov 2017 05:46:31 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/scsi/aacraid/commsup.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) -- 2.9.0 Reviewed-by: Dave Carroll 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)