Message ID | 20240524095719.105284-1-hare@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | block: check for max_hw_sectors underflow | expand |
On Fri, May 24, 2024 at 11:57:19AM +0200, Hannes Reinecke wrote:
> + if (WARN_ON_ONCE((lim->logical_block_size >> SECTOR_SHIFT) > lim->max_hw_sectors))
Please avoid the overly long line.
On 5/24/24 02:57, Hannes Reinecke wrote: > diff --git a/block/blk-settings.c b/block/blk-settings.c > index 524cf597b2e9..0cdca702e988 100644 > --- a/block/blk-settings.c > +++ b/block/blk-settings.c > @@ -133,6 +133,8 @@ static int blk_validate_limits(struct queue_limits *lim) > lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS; > if (WARN_ON_ONCE(lim->max_hw_sectors < PAGE_SECTORS)) > return -EINVAL; > + if (WARN_ON_ONCE((lim->logical_block_size >> SECTOR_SHIFT) > lim->max_hw_sectors)) > + return -EINVAL; > lim->max_hw_sectors = round_down(lim->max_hw_sectors, > lim->logical_block_size >> SECTOR_SHIFT); > Why is lim->max_hw_sectors checked before calling round_down() instead of checking that round_down() returns zero? Thanks, Bart.
diff --git a/block/blk-settings.c b/block/blk-settings.c index 524cf597b2e9..0cdca702e988 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -133,6 +133,8 @@ static int blk_validate_limits(struct queue_limits *lim) lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS; if (WARN_ON_ONCE(lim->max_hw_sectors < PAGE_SECTORS)) return -EINVAL; + if (WARN_ON_ONCE((lim->logical_block_size >> SECTOR_SHIFT) > lim->max_hw_sectors)) + return -EINVAL; lim->max_hw_sectors = round_down(lim->max_hw_sectors, lim->logical_block_size >> SECTOR_SHIFT);
The logical block size need to be smaller than the max_hw_sector setting, otherwise we can't even transfer a single LBA. Signed-off-by: Hannes Reinecke <hare@kernel.org> --- block/blk-settings.c | 2 ++ 1 file changed, 2 insertions(+)