block: check for max_hw_sectors underflow
Subsystems (2)
PATCH 1/1 block: check for max_hw_sectors underflow
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 <[email protected]>
--- block/blk-settings.c | 2 ++ 1 file changed, 2 insertions(+)
block/blk-settings.c +2 -0
@@ -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 );
Signature · 1 line
2.35.3
block/blk-settings.c static int blk_validate_limits(struct queue_limits *lim) · line 136
Quoted 1 line · Hannes Reinecke
block/blk-settings.c +1
-0+if (WARN_ON_ONCE ((lim->logical_block_size >>SECTOR_SHIFT ) > lim->max_hw_sectors))
Please avoid the overly long line.
block/blk-settings.c static int blk_validate_limits(struct queue_limits *lim) · line 140
Quoted 13 lines · Hannes Reinecke
block/blk-settings.c +2
-0@@ -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.