[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <112e58d8-8a70-4aed-bf42-df4cdf47c0d2@kernel.org>
Date: Tue, 9 Jul 2024 14:38:39 +0900
From: Damien Le Moal <dlemoal@...nel.org>
To: John Garry <john.g.garry@...cle.com>, axboe@...nel.dk, mst@...hat.com,
jasowang@...hat.com, xuanzhuo@...ux.alibaba.com, eperezma@...hat.com,
pbonzini@...hat.com, stefanha@...hat.com, hare@...e.de, kbusch@...nel.org,
hch@....de
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
virtualization@...ts.linux.dev
Subject: Re: [PATCH v2 2/5] block: Validate logical block size in
blk_validate_limits()
On 7/8/24 18:16, John Garry wrote:
> 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@...cle.com>
> ---
> block/blk-settings.c | 4 ++++
> include/linux/blkdev.h | 1 +
> 2 files changed, 5 insertions(+)
>
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 9fa4eed4df06..cd8a8eabc9a5 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -235,6 +235,10 @@ static int blk_validate_limits(struct queue_limits *lim)
> */
> if (!lim->logical_block_size)
> lim->logical_block_size = SECTOR_SIZE;
> + else if (blk_validate_block_size(lim->logical_block_size)) {
> + pr_warn("Invalid logical block size (%d)\n", lim->logical_block_size);
logical_block_size is an unsigned int so this needs to use %u.
With this nit fixed, feel free to add:
Reviewed-by: Damien Le Moal <dlemoal@...nel.org>
> + return -EINVAL;
> + }
> if (lim->physical_block_size < lim->logical_block_size)
> lim->physical_block_size = lim->logical_block_size;
>
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 02e04df27282..dce4a6bf7307 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -268,6 +268,7 @@ static inline dev_t disk_devt(struct gendisk *disk)
> return MKDEV(disk->major, disk->first_minor);
> }
>
> +/* blk_validate_limits() validates bsize, so drivers don't usually need to */
> static inline int blk_validate_block_size(unsigned long bsize)
> {
> if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
--
Damien Le Moal
Western Digital Research
Powered by blists - more mailing lists