From: Ching Huang <ching2048@areca.com.tw>
To: Arnd Bergmann <arnd@arndb.de>
Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
y2038@lists.linaro.org, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: arcmsr: avoid do_gettimeofday
Date: Mon, 22 Jan 2018 19:06:10 +0800 [thread overview]
Message-ID: <1516619170.4452.3.camel@Centos6.3-64> (raw)
In-Reply-To: <20180121231308.2169692-1-arnd@arndb.de>
On Mon, 2018-01-22 at 00:12 +0100, Arnd Bergmann wrote:
> The arcmsr uses its own implementation of time_to_tm(), along with do_gettimeofday()
> to read the current time. While the algoritm used here is fine in principle, it
> suffers from two problems:
>
> - it assigns the seconds portion of the timeval to a 32-bit unsigned integer that
> overflows in 2106 even on 64-bit architectures.
> - do_gettimeofday() returns a time_t that overflows in 2038 on all 32-bit systems.
>
> This changes the time retrieval function to ktime_get_real_seconds(), which returns
> a proper 64-bit value, and replaces the open-coded time_to_tm() algorithm with
> a call to the safe time64_to_tm().
>
> I checked way all numbers are indexed and found that months are given in range
> 0..11 while the days are in range 1..31, same as 'struct tm', but the year value
> that the firmware expects starts in 2000 while 'struct tm' is based on year 1900,
> so it needs a small adjustment.
>
> Fixes: b416c099472a ("scsi: arcmsr: Add a function to set date and time to firmware")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/scsi/arcmsr/arcmsr_hba.c | 37 ++++++++++---------------------------
> 1 file changed, 10 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
> index 47745592cff4..75e828bd30e3 100644
> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
> @@ -3489,8 +3489,9 @@ static int arcmsr_polling_ccbdone(struct AdapterControlBlock *acb,
> static void arcmsr_set_iop_datetime(struct timer_list *t)
> {
> struct AdapterControlBlock *pacb = from_timer(pacb, t, refresh_timer);
> - unsigned int days, j, i, a, b, c, d, e, m, year, mon, day, hour, min, sec, secs, next_time;
> - struct timeval tv;
> + unsigned int next_time;
> + struct tm tm;
> +
> union {
> struct {
> uint16_t signature;
> @@ -3506,33 +3507,15 @@ static void arcmsr_set_iop_datetime(struct timer_list *t)
> } b;
> } datetime;
>
> - do_gettimeofday(&tv);
> - secs = (u32)(tv.tv_sec - (sys_tz.tz_minuteswest * 60));
> - days = secs / 86400;
> - secs = secs - 86400 * days;
> - j = days / 146097;
> - i = days - 146097 * j;
> - a = i + 719468;
> - b = ( 4 * a + 3 ) / 146097;
> - c = a - ( 146097 * b ) / 4;
> - d = ( 4 * c + 3 ) / 1461 ;
> - e = c - ( 1461 * d ) / 4 ;
> - m = ( 5 * e + 2 ) / 153 ;
> - year = 400 * j + 100 * b + d + m / 10 - 2000;
> - mon = m + 3 - 12 * ( m /10 );
> - day = e - ( 153 * m + 2 ) / 5 + 1;
> - hour = secs / 3600;
> - secs = secs - 3600 * hour;
> - min = secs / 60;
> - sec = secs - 60 * min;
> + time64_to_tm(ktime_get_real_seconds(), -sys_tz.tz_minuteswest * 60, &tm);
>
> datetime.a.signature = 0x55AA;
> - datetime.a.year = year;
> - datetime.a.month = mon;
> - datetime.a.date = day;
> - datetime.a.hour = hour;
> - datetime.a.minute = min;
> - datetime.a.second = sec;
> + datetime.a.year = tm.tm_year - 100; /* base 2000 instead of 1900 */
> + datetime.a.month = tm.tm_mon;
> + datetime.a.date = tm.tm_mday;
> + datetime.a.hour = tm.tm_hour;
> + datetime.a.minute = tm.tm_min;
> + datetime.a.second = tm.tm_sec;
>
> switch (pacb->adapter_type) {
> case ACB_ADAPTER_TYPE_A: {
This patch works on kernel 4.14.0, thanks Arnd.
next prev parent reply other threads:[~2018-01-22 11:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-21 23:12 [PATCH] scsi: arcmsr: avoid do_gettimeofday Arnd Bergmann
2018-01-22 11:06 ` Ching Huang [this message]
2018-01-23 0:31 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1516619170.4452.3.camel@Centos6.3-64 \
--to=ching2048@areca.com.tw \
--cc=arnd@arndb.de \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=y2038@lists.linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox