diff mbox series

scsi: fix the return value of scsi_logical_block_count

Message ID 20240806072714.29756-1-chaotian.jing@mediatek.com
State Superseded
Headers show
Series scsi: fix the return value of scsi_logical_block_count | expand

Commit Message

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

Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
---
 include/scsi/scsi_cmnd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bart Van Assche Aug. 6, 2024, 8:51 p.m. UTC | #1
On 8/6/24 12:26 AM, Chaotian Jing wrote:
> scsi_logical_block_count() should return the block count of scsi device,
> but the original code has a wrong implement.
> 
> Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
> ---
>   include/scsi/scsi_cmnd.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 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;
>   }
>   
>   /*

Please add the following to this patch:

Cc: stable@vger.kernel.org
Fixes: 6a20e21ae1e2 ("scsi: core: Add helper to return number of logical 
blocks in a request")

Anyway:

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
John Garry Aug. 7, 2024, 8:47 a.m. UTC | #2
On 06/08/2024 08:26, Chaotian Jing wrote:
> scsi_logical_block_count() should return the block count of scsi device,

scsi command, not scsi device

> but the original code has a wrong implement.
> 
> Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
> ---
>   include/scsi/scsi_cmnd.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 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)

I find it questionable why we have this in the core code, since it's 
only used in error handling logs for one driver. And obviously no one 
was paying attention to it.

>   {
>   	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;

blk_rq_sectors() converts from bytes to linux sectors, and then we shift 
it by diff in linux sectors and LBS.

To me, if this were used in fastpath - which it isn't - the following 
seems better:

return blk_rq_bytes(scsi_cmd_to_rq(scmd)) / scmd->device->sector_size;

>   }
>   
>   /*
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;
 }
 
 /*