Skip to content

Commit

Permalink
lib: fix bitmap_parse() on 64-bit big endian archs
Browse files Browse the repository at this point in the history
Commit 2d62615 ("lib: rework bitmap_parse()") does not take into
account order of halfwords on 64-bit big endian architectures.  As
result (at least) Receive Packet Steering, IRQ affinity masks and
runtime kernel test "test_bitmap" get broken on s390.

[[email protected]: convert infinite while loop to a for loop]
  Link: http://lkml.kernel.org/r/[email protected]

Fixes: 2d62615 ("lib: rework bitmap_parse()")
Signed-off-by: Alexander Gordeev <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Cc: Yury Norov <[email protected]>
Cc: Amritha Nambiar <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Chris Wilson <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Steffen Klassert <[email protected]>
Cc: "Tobin C . Harding" <[email protected]>
Cc: Vineet Gupta <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Willem de Bruijn <[email protected]>
Cc: <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Alexander Gordeev authored and torvalds committed Jun 11, 2020
1 parent 2581ac7 commit 81c4f4d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,16 +741,21 @@ int bitmap_parse(const char *start, unsigned int buflen,
int chunks = BITS_TO_U32(nmaskbits);
u32 *bitmap = (u32 *)maskp;
int unset_bit;
int chunk;

while (1) {
for (chunk = 0; ; chunk++) {
end = bitmap_find_region_reverse(start, end);
if (start > end)
break;

if (!chunks--)
return -EOVERFLOW;

end = bitmap_get_x32_reverse(start, end, bitmap++);
#if defined(CONFIG_64BIT) && defined(__BIG_ENDIAN)
end = bitmap_get_x32_reverse(start, end, &bitmap[chunk ^ 1]);
#else
end = bitmap_get_x32_reverse(start, end, &bitmap[chunk]);
#endif
if (IS_ERR(end))
return PTR_ERR(end);
}
Expand Down

0 comments on commit 81c4f4d

Please sign in to comment.