lkml.org 
[lkml]   [2018]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH][next] afs: fix integer overflow when shifting 1 more than 32 places
From
Date
On 11/04/18 15:10, David Howells wrote:
> Colin Ian King <colin.king@canonical.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.

I'm not sure that actually helps, 1 << nr_slots is still evaluating as
a 32 bit value, so that final cast does not may any difference. Anyhow,
since nr_slots is less than 32 then keeping it the way it was is fine.

>
> David
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

\
 
 \ /
  Last update: 2018-04-11 16:19    [W:0.062 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site