]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
bcachefs: fix build on 32 bit in get_random_u64_below()
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 14 Mar 2025 22:20:20 +0000 (18:20 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 14 Mar 2025 23:45:54 +0000 (19:45 -0400)
bare 64 bit divides not allowed, whoops

arm-linux-gnueabi-ld: drivers/char/random.o: in function `__get_random_u64_below':
drivers/char/random.c:602:(.text+0xc70): undefined reference to `__aeabi_uldivmod'

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/util.c

index 8e3ab4bf79a90628757f7abb1d66568656065250..da2cd11b3025d5ae2330b8afdbfc14c9fa065f93 100644 (file)
@@ -663,7 +663,8 @@ u64 bch2_get_random_u64_below(u64 ceil)
        u64 mult = ceil * rand;
 
        if (unlikely(mult < ceil)) {
-               u64 bound = -ceil % ceil;
+               u64 bound;
+               div64_u64_rem(-ceil, ceil, &bound);
                while (unlikely(mult < bound)) {
                        rand = get_random_u64();
                        mult = ceil * rand;