Message ID | 20250613062909.2505759-2-dlemoal@kernel.org |
---|---|
State | New |
Headers | show |
Series | Improve optimal IO size initialization | expand |
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 36382eca941c..53658679e063 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -213,9 +213,9 @@ static inline sector_t logical_to_sectors(struct scsi_device *sdev, sector_t blo return blocks << (ilog2(sdev->sector_size) - 9); } -static inline unsigned int logical_to_bytes(struct scsi_device *sdev, sector_t blocks) +static inline u64 logical_to_bytes(struct scsi_device *sdev, sector_t blocks) { - return blocks * sdev->sector_size; + return (u64)blocks << ilog2(sdev->sector_size); } static inline sector_t bytes_to_logical(struct scsi_device *sdev, unsigned int bytes)
Make sure that logical_to_bytes() does not return an overflowed value by changing its return type from unsigned int (32-bits) to u64 (64-bits). And while at it, also use a bit-shift instead of a multiplication, similar to logical_to_sectors() and bytes_to_logical(). Signed-off-by: Damien Le Moal <dlemoal@kernel.org> --- drivers/scsi/sd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)