Date: Fri, 4 Aug 2017 06:40:41 +0000 From: Colin Percival <cperciva@tarsnap.com> To: Hans Petter Selasky <hps@selasky.org>, cem@freebsd.org Cc: src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r321985 - head/sys/ofed/drivers/infiniband/core Message-ID: <0100015dabf98040-76cfbcc7-5de4-4e35-9a90-60fa54d31563-000000@email.amazonses.com> In-Reply-To: <bd19c6f8-fa97-c9c5-6318-1778e38dd0a9@selasky.org> References: <201708030918.v739IPVY034866@repo.freebsd.org> <CAG6CVpVL49nVqRs5atub=d2P39EGOqcNtx_Raa8fWtV=BFZXbw@mail.gmail.com> <bd19c6f8-fa97-c9c5-6318-1778e38dd0a9@selasky.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 08/03/17 23:28, Hans Petter Selasky wrote: > On 08/03/17 16:37, Conrad Meyer wrote: >> Is it not important that the subtraction and result are evaluated >> without truncation? > > ticks is a circular counter. Assuming time = 0 and jiffies = -1U, then "delay" > becomes a very large negative value, because long is used, and the delay <= 0 > check, is no longer working like expected. > > Casting to "int" or truncating is the right thing to do in this case. Signed integer overflow is undefined. Using 'int' is liable to cause problems after 2^32 ticks. Colin Percival >>> Log: >>> Ticks are 32-bit in FreeBSD. >>> >>> MFC after: 3 days >>> Sponsored by: Mellanox Technologies >>> >>> Modified: >>> head/sys/ofed/drivers/infiniband/core/addr.c >>> >>> Modified: head/sys/ofed/drivers/infiniband/core/addr.c >>> ============================================================================== >>> --- head/sys/ofed/drivers/infiniband/core/addr.c Thu Aug 3 09:14:43 >>> 2017 (r321984) >>> +++ head/sys/ofed/drivers/infiniband/core/addr.c Thu Aug 3 09:18:25 >>> 2017 (r321985) >>> @@ -187,10 +187,10 @@ EXPORT_SYMBOL(rdma_translate_ip); >>> >>> static void set_timeout(unsigned long time) >>> { >>> - unsigned long delay; >>> + int delay; /* under FreeBSD ticks are 32-bit */ >>> >>> delay = time - jiffies; >>> - if ((long)delay <= 0) >>> + if (delay <= 0) >>> delay = 1; >>> >>> mod_delayed_work(addr_wq, &work, delay); -- Colin Percival Security Officer Emeritus, FreeBSD | The power to serve Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0100015dabf98040-76cfbcc7-5de4-4e35-9a90-60fa54d31563-000000>