Skip to content

Commit fe3d508

Browse files
johnpgarryaxboe
authored andcommitted
block: Validate logical block size in blk_validate_limits()
Some drivers validate that their own logical block size. It is no harm to always do this, so validate in blk_validate_limits(). This allows us to remove the validation in most of those drivers. Add a comment to blk_validate_block_size() to inform users that self- validation of LBS is usually unnecessary. Signed-off-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Link: https://lore.kernel.org/r/20240708091651.177447-3-john.g.garry@oracle.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 4ff3d01 commit fe3d508

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

block/blk-settings.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ static int blk_validate_limits(struct queue_limits *lim)
235235
*/
236236
if (!lim->logical_block_size)
237237
lim->logical_block_size = SECTOR_SIZE;
238+
else if (blk_validate_block_size(lim->logical_block_size)) {
239+
pr_warn("Invalid logical block size (%d)\n", lim->logical_block_size);
240+
return -EINVAL;
241+
}
238242
if (lim->physical_block_size < lim->logical_block_size)
239243
lim->physical_block_size = lim->logical_block_size;
240244

include/linux/blkdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ static inline dev_t disk_devt(struct gendisk *disk)
268268
return MKDEV(disk->major, disk->first_minor);
269269
}
270270

271+
/* blk_validate_limits() validates bsize, so drivers don't usually need to */
271272
static inline int blk_validate_block_size(unsigned long bsize)
272273
{
273274
if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))

0 commit comments

Comments
 (0)