[PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors

Keith Busch kbusch at kernel.org
Mon Aug 16 14:43:13 PDT 2021


On Tue, Aug 17, 2021 at 02:11:01AM +0800, Tom Yan wrote:
> The block layer uses UINT_MAX for maximums in bytes.

Nak, the code is correct as-is. A UINT_MAX number of sectors is
valid when the device doesn't have an upper limit.

> Signed-off-by: Tom Yan <tom.ty89 at gmail.com>
> ---
>  drivers/nvme/host/core.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index dfd9dec0c1f6..3a1bfb45da2a 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1640,7 +1640,7 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
>  	blk_queue_max_discard_segments(queue, ctrl->max_discard_segments);
>  
>  	if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
> -		blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
> +		blk_queue_max_write_zeroes_sectors(queue, UINT_MAX >> SECTOR_SHIFT);
>  }
>  
>  static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
> @@ -2762,7 +2762,7 @@ static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units)
>  	u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val;
>  
>  	if (check_shl_overflow(1U, units + page_shift - 9, &val))
> -		return UINT_MAX;
> +		return UINT_MAX >> SECTOR_SHIFT;
>  	return val;
>  }
>  
> @@ -2773,7 +2773,7 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
>  	int ret;
>  
>  	if (ctrl->oncs & NVME_CTRL_ONCS_DSM) {
> -		ctrl->max_discard_sectors = UINT_MAX;
> +		ctrl->max_discard_sectors = UINT_MAX >> SECTOR_SHIFT;
>  		ctrl->max_discard_segments = NVME_DSM_MAX_RANGES;
>  	} else {
>  		ctrl->max_discard_sectors = 0;
> @@ -2883,7 +2883,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
>  	if (id->mdts)
>  		max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts);
>  	else
> -		max_hw_sectors = UINT_MAX;
> +		max_hw_sectors = UINT_MAX >> SECTOR_SHIFT;
>  	ctrl->max_hw_sectors =
>  		min_not_zero(ctrl->max_hw_sectors, max_hw_sectors);
>  
> -- 



More information about the Linux-nvme mailing list