Commit 2d6261583be0 ("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.

Fixes: 2d6261583be0 ("lib: rework bitmap_parse()")
Cc: sta...@vger.kernel.org
Cc: Andrew Morton <a...@linux-foundation.org>
Cc: Yury Norov <yury.no...@gmail.com>
Cc: Andy Shevchenko <andriy.shevche...@linux.intel.com>
Cc: Amritha Nambiar <amritha.namb...@intel.com>
Cc: Arnaldo Carvalho de Melo <a...@redhat.com>
Cc: Chris Wilson <ch...@chris-wilson.co.uk>
Cc: Kees Cook <keesc...@chromium.org>
Cc: Matthew Wilcox <wi...@infradead.org>
Cc: Miklos Szeredi <mszer...@redhat.com>
Cc: Rasmus Villemoes <li...@rasmusvillemoes.dk>
Cc: Steffen Klassert <steffen.klass...@secunet.com>
Cc: "Tobin C . Harding" <to...@kernel.org>
Cc: Vineet Gupta <vineet.gup...@synopsys.com>
Cc: Will Deacon <will.dea...@arm.com>
Cc: Willem de Bruijn <will...@google.com>
Signed-off-by: Alexander Gordeev <agord...@linux.ibm.com>
---
 lib/bitmap.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index 89260aa342d6..80d26b183248 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -739,6 +739,7 @@ int bitmap_parse(const char *start, unsigned int buflen,
        const char *end = strnchrnul(start, buflen, '\n') - 1;
        int chunks = BITS_TO_U32(nmaskbits);
        u32 *bitmap = (u32 *)maskp;
+       int chunk = 0;
        int unset_bit;
 
        while (1) {
@@ -749,9 +750,14 @@ int bitmap_parse(const char *start, unsigned int buflen,
                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);
+               chunk++;
        }
 
        unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32;
-- 
2.23.0

Reply via email to