[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180411155811.2qznymjhi6zlzgbb@mwanda>
Date: Wed, 11 Apr 2018 18:58:12 +0300
From: Dan Carpenter <dan.carpenter@...cle.com>
To: David Howells <dhowells@...hat.com>
Cc: Colin Ian King <colin.king@...onical.com>,
linux-afs@...ts.infradead.org, kernel-janitors@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH][next] afs: fix integer overflow when shifting 1 more
than 32 places
On Wed, Apr 11, 2018 at 03:10:16PM +0100, David Howells wrote:
> Colin Ian King <colin.king@...onical.com> wrote:
>
> > >> - mask = (1 << nr_slots) - 1;
> > >> + mask = (1ULL << nr_slots) - 1;
> > >
> > > nr_slots cannot be larger than 9, so what I wrote is actually fine and is
> > > more efficient on a 32-bit machine.
> >
> > ok, sorry about the noise.
>
> It would be possible to cast the value to u64 before assigning it, I suppose.
> Would that help? E.g.:
>
> mask = (u64)((1 << nr_slots) - 1);
>
> It looks a bit odd, though, since the cast is made implicitly anyway.
My feeling is that makes it worse. It would introduce a secret,
unpublished static checker warning on my build and it doesn't help me as
a reviewer.
Ideally static analyzers should know that nr_slots is 0-9, but right now
that seems pretty tricky to figure out...
regards,
dan carpenter
Powered by blists - more mailing lists