Skip to contentSkip to conversation

block: check for max_hw_sectors underflow

PATCH Superseded Hannes Reinecke 3 participants 3 messages May 24, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

---
 block/blk-settings.c | 2 ++
 1 file changed, 2 insertions(+)
block/blk-settings.c +2 -0
index 524cf597b2e9..0cdca702e988 100644
@@ -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
#1 lore raw

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.

#2 lore raw
In reply to Hannes Reinecke

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
index 524cf597b2e9..0cdca702e988 100644
@@ -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.