On 22/07/2025 12:28, Hannes Reinecke wrote:
The merging/splitting code and other queue limits checking depends on the
physical block size being a power-of-2, so enforce it.
Signed-off-by: John Garry <john.g.garry@xxxxxxxxxx>
---
block/blk-settings.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index fa53a330f9b9..5ae0a253e43f 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -274,6 +274,10 @@ int blk_validate_limits(struct queue_limits *lim)
}
if (lim->physical_block_size < lim->logical_block_size)
lim->physical_block_size = lim->logical_block_size;
+ else if (!is_power_of_2(lim->physical_block_size)) {
+ pr_warn("Invalid physical block size (%d)\n", lim-
>physical_block_size);
+ return -EINVAL;
+ }
/*
* The minimum I/O size defaults to the physical block size unless
Why not calling 'blk_validate_block_size()' here?
blk_validate_block_size() enforces that that size cannot be greater than
64K - does such a limit exist for the physical block size?
Incidentally blk_validate_block_size() also checks that the size is not
less then SECTOR_SIZE, which would never be true in
blk_validate_limits() for the physical block size. But duplicating such
a check is not a huge deal.
Thanks,
John