]> www.infradead.org Git - users/hch/configfs.git/commitdiff
bcachefs: Don't rely on implicit unsigned -> signed integer conversion
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 31 Jul 2024 00:33:25 +0000 (20:33 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 7 Aug 2024 12:31:10 +0000 (08:31 -0400)
implicit integer conversion is a fertile source of bugs, and we really
would rather not have the min()/max() macros doing it implicitly.
bcachefs appears to be the only place in the kernel where this happens,
so let's fix it.

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

index 8d2b62c9588e738364da6aab03000f271604fd5a..f13e619b4b2153e29a64fadba9d1175ca905bced 100644 (file)
@@ -166,8 +166,8 @@ static inline u64 alloc_lru_idx_fragmentation(struct bch_alloc_v4 a,
         * avoid overflowing LRU_TIME_BITS on a corrupted fs, when
         * bucket_sectors_dirty is (much) bigger than bucket_size
         */
-       u64 d = min(bch2_bucket_sectors_dirty(a),
-                   ca->mi.bucket_size);
+       u64 d = min_t(s64, bch2_bucket_sectors_dirty(a),
+                     ca->mi.bucket_size);
 
        return div_u64(d * (1ULL << 31), ca->mi.bucket_size);
 }