From edfbb7e18086e898fea282b4d350b26c5c792739 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 23 Mar 2026 12:02:14 +0100 Subject: [PATCH] block: Add DISCARD_WZ_MAX_PAYLOAD constant Introduce DISCARD_WZ_MAX_PAYLOAD as the precomputed product of DISCARD_WZ_SEG_SIZE and MAX_DISCARD_WRITE_ZEROES_SEG. Use it in the DISCARD and WRITE_ZEROES segment count checks instead of repeating the multiplication inline. Suggested-by: Philipp Schuster Signed-off-by: Anatol Belski --- block/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/src/lib.rs b/block/src/lib.rs index 81b3f27c0..e6b23b387 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -75,6 +75,7 @@ pub const MAX_DISCARD_WRITE_ZEROES_SEG: u32 = 1; /// Size and field offsets within `struct virtio_blk_discard_write_zeroes`. const DISCARD_WZ_SEG_SIZE: u32 = mem::size_of::() as u32; +const DISCARD_WZ_MAX_PAYLOAD: u32 = DISCARD_WZ_SEG_SIZE * MAX_DISCARD_WRITE_ZEROES_SEG; const DISCARD_WZ_SECTOR_OFFSET: u64 = mem::offset_of!(virtio_blk_discard_write_zeroes, sector) as u64; const DISCARD_WZ_NUM_SECTORS_OFFSET: u64 = @@ -600,7 +601,7 @@ impl Request { if data_len < DISCARD_WZ_SEG_SIZE { return Err(ExecuteError::BadRequest(Error::DescriptorLengthTooSmall)); } - if data_len > DISCARD_WZ_SEG_SIZE * MAX_DISCARD_WRITE_ZEROES_SEG { + if data_len > DISCARD_WZ_MAX_PAYLOAD { return Err(ExecuteError::BadRequest(Error::TooManySegments)); } @@ -649,7 +650,7 @@ impl Request { if data_len < DISCARD_WZ_SEG_SIZE { return Err(ExecuteError::BadRequest(Error::DescriptorLengthTooSmall)); } - if data_len > DISCARD_WZ_SEG_SIZE * MAX_DISCARD_WRITE_ZEROES_SEG { + if data_len > DISCARD_WZ_MAX_PAYLOAD { return Err(ExecuteError::BadRequest(Error::TooManySegments)); }