On Thu, Feb 4, 2016 at 1:46 PM, Linus Torvalds <torva...@linux-foundation.org> wrote: > > static const unsigned long mask[9] = { > 0x0000000000000000, > 0x000000000000ff00, > 0x000000000000ffff, > 0x00000000ff00ffff, > 0x00000000ffffffff, > 0x0000ff00ffffffff, > 0x0000ffffffffffff, > 0xff00ffffffffffff, > 0xffffffffffffffff }; > unsigned long val = load_unaligned_zeropad(buf + (len & 1)); > val &= mask[len];
Yeah, that was buggy. I knew it was likely buggy, but that "buf + (len & 1)" was just stupid. The "+" should be "-", of course - the point is to shift up the value by 8 bits for odd cases, and we need to load starting one byte early for that. The idea is that we use the byte shifter in the load unit to do some work for us. And the bitmasks are the wrong way around for the odd cases - it's the low byte that ends up being bogus for those cases. So it should probably look something like static const unsigned long mask[9] = { 0x0000000000000000, 0x000000000000ff00, 0x000000000000ffff, 0x00000000ffffff00, 0x00000000ffffffff, 0x0000ffffffffff00, 0x0000ffffffffffff, 0xffffffffffffff00, 0xffffffffffffffff }; unsigned long val = load_unaligned_zeropad(buf - (len & 1)); val &= mask[len]; and then it *might* work. Still entirely and utterly untested, I just decided to look at it a bit more and noticed my thinko. Linus