diff mbox series

scsi: fix the return value of scsi_logical_block_count

Message ID 20240807005907.12380-1-chaotian.jing@mediatek.com (mailing list archive)
State Superseded
Headers show
Series scsi: fix the return value of scsi_logical_block_count | expand

Commit Message

Chaotian Jing Aug. 7, 2024, 12:57 a.m. UTC
scsi_logical_block_count() should return the block count of scsi device,
but the original code has a wrong implement.

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>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
---
 include/scsi/scsi_cmnd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Martin K. Petersen Aug. 13, 2024, 1:52 a.m. UTC | #1
Chaotian,

> @@ -236,7 +236,7 @@ static inline unsigned int scsi_logical_block_count(struct scsi_cmnd *scmd)
>  {
>  	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
>  
> -	return blk_rq_bytes(scsi_cmd_to_rq(scmd)) >> shift;
> +	return blk_rq_sectors(scsi_cmd_to_rq(scmd)) >> shift;
>  }

There's no point in shifting twice by converting to sectors first.
Please just remove the SECTOR_SHIFT subtraction.
Chaotian Jing Aug. 13, 2024, 3:35 a.m. UTC | #2
On Mon, 2024-08-12 at 21:52 -0400, Martin K. Petersen wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  
> Chaotian,
> 
> > @@ -236,7 +236,7 @@ static inline unsigned int
> scsi_logical_block_count(struct scsi_cmnd *scmd)
> >  {
> >  	unsigned int shift = ilog2(scmd->device->sector_size) -
> SECTOR_SHIFT;
> >  
> > -	return blk_rq_bytes(scsi_cmd_to_rq(scmd)) >> shift;
> > +	return blk_rq_sectors(scsi_cmd_to_rq(scmd)) >> shift;
> >  }
> 
> There's no point in shifting twice by converting to sectors first.
> Please just remove the SECTOR_SHIFT subtraction.
> 
Thanks, will fix it at next version.
> -- 
> Martin K. Petersen	Oracle Linux Engineering
diff mbox series

Patch

diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 45c40d200154..f0be0caa295a 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -236,7 +236,7 @@  static inline unsigned int scsi_logical_block_count(struct scsi_cmnd *scmd)
 {
 	unsigned int shift = ilog2(scmd->device->sector_size) - SECTOR_SHIFT;
 
-	return blk_rq_bytes(scsi_cmd_to_rq(scmd)) >> shift;
+	return blk_rq_sectors(scsi_cmd_to_rq(scmd)) >> shift;
 }
 
 /*