]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: mean_and_variance: Avoid too-large shift amounts
authorTavian Barnes <tavianator@tavianator.com>
Fri, 21 Jun 2024 20:38:44 +0000 (16:38 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 18 Jul 2024 22:33:30 +0000 (18:33 -0400)
Shifting a value by the width of its type or more is undefined.

Signed-off-by: Tavian Barnes <tavianator@tavianator.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/mean_and_variance.h

index 4fcf062dd22c71efd338a9ab37a8e1af5ca22ce5..47e4a3c3d26e73848a709f45130b8e255454c35d 100644 (file)
@@ -111,11 +111,11 @@ static inline u128_u u128_shl(u128_u i, s8 shift)
 {
        u128_u r;
 
-       r.lo = i.lo << shift;
+       r.lo = i.lo << (shift & 63);
        if (shift < 64)
-               r.hi = (i.hi << shift) | (i.lo >> (64 - shift));
+               r.hi = (i.hi << (shift & 63)) | (i.lo >> (-shift & 63));
        else {
-               r.hi = i.lo << (shift - 64);
+               r.hi = i.lo << (-shift & 63);
                r.lo = 0;
        }
        return r;