Skip to content

Commit

Permalink
scsi: core: Fix the return value of scsi_logical_block_count()
Browse files Browse the repository at this point in the history
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: 6a20e21 ("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>
  • Loading branch information
Chaotian Jing authored and Martin K. Petersen committed Aug 17, 2024
1 parent 2fa62ce commit f03e94f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/scsi/scsi_cmnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f03e94f

Please sign in to comment.