]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: core: Fix the return value of scsi_logical_block_count()
authorChaotian Jing <chaotian.jing@mediatek.com>
Tue, 13 Aug 2024 05:34:10 +0000 (13:34 +0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Sat, 17 Aug 2024 01:02:06 +0000 (21:02 -0400)
scsi_logical_block_count() should return the block count of a given SCSI
command. The original implementation ended up shifting twice, leading to an
incorrect count being returned. Fix the conversion between bytes and
logical blocks.

Cc: stable@vger.kernel.org
Fixes: 6a20e21ae1e2 ("scsi: core: Add helper to return number of logical blocks in a request")
Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
Link: https://lore.kernel.org/r/20240813053534.7720-1-chaotian.jing@mediatek.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
include/scsi/scsi_cmnd.h

index 45c40d200154dd075c785a055d37f9ec8f131456..8ecfb94049db5186f9d6dfc86c627ae66cea6e05 100644 (file)
@@ -234,7 +234,7 @@ static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
 
 static inline unsigned int scsi_logical_block_count(struct scsi_cmnd *scmd)
 {
-       unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
+       unsigned int shift = ilog2(scmd->device->sector_size);
 
        return blk_rq_bytes(scsi_cmd_to_rq(scmd)) >> shift;
 }