From 5a77c19c8f4a7e1b8457baf98e6939e6c410b9ee Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Mon, 10 Nov 2025 16:58:39 -0500 Subject: [PATCH] BRT: Fix ranges to blocks conversion math BRT_RANGESIZE_TO_NBLOCKS() takes number of ranges as its argument. To get number of blocks we should multiply it by the entry size, not divide by it, as it was due to missing parentheses. Before #17875 this could cause small memory corruptions for vdevs bigger than 64TB, but the change made the bug more noticeable. Reviewed-by: Brian Behlendorf Signed-off-by: Alexander Motin Closes #17886 Closes #17915 --- include/sys/brt_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sys/brt_impl.h b/include/sys/brt_impl.h index 9cc06fbb2..ce9c6156c 100644 --- a/include/sys/brt_impl.h +++ b/include/sys/brt_impl.h @@ -64,7 +64,7 @@ _Static_assert(BRT_RANGESIZE / SPA_MINBLOCKSIZE <= UINT16_MAX, */ #define BRT_BLOCKSIZE (32 * 1024) #define BRT_RANGESIZE_TO_NBLOCKS(size) \ - (((size) - 1) / BRT_BLOCKSIZE / sizeof (uint16_t) + 1) + (((size) - 1) / (BRT_BLOCKSIZE / sizeof (uint16_t)) + 1) #define BRT_LITTLE_ENDIAN 0 #define BRT_BIG_ENDIAN 1