diff mbox series

[05/11] block: Limit allocation of zone descriptors for report zones

Message ID 20181010015239.24930-6-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series Zoned block device support improvements | expand

Commit Message

Damien Le Moal Oct. 10, 2018, 1:52 a.m. UTC
There is no point in allocating more zone descriptors than the number of
zones a block device has for doing a zone report. Avoid doing that in
blkdev_report_zones_ioctl() by limiting the number of zone decriptors
allocated internally to process the user request.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/blk-zoned.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Oct. 10, 2018, 1:27 p.m. UTC | #1
> +	unsigned int nr_zones;
>  	int ret;
>  
>  	if (!argp)
> @@ -355,8 +356,9 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
>  	if (!rep.nr_zones)
>  		return -EINVAL;
>  
> -	if (rep.nr_zones > INT_MAX / sizeof(struct blk_zone))
> -		return -ERANGE;
> +	nr_zones = blkdev_nr_zones(bdev);
> +	if (rep.nr_zones > nr_zones)
> +		rep.nr_zones = nr_zones;

This could be further simplified using min_t, but othewise it looks fine
to me:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 32e377f755d8..f2c8b859fc18 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -334,6 +334,7 @@  int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
 	struct request_queue *q;
 	struct blk_zone_report rep;
 	struct blk_zone *zones;
+	unsigned int nr_zones;
 	int ret;
 
 	if (!argp)
@@ -355,8 +356,9 @@  int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
 	if (!rep.nr_zones)
 		return -EINVAL;
 
-	if (rep.nr_zones > INT_MAX / sizeof(struct blk_zone))
-		return -ERANGE;
+	nr_zones = blkdev_nr_zones(bdev);
+	if (rep.nr_zones > nr_zones)
+		rep.nr_zones = nr_zones;
 
 	zones = kvmalloc_array(rep.nr_zones, sizeof(struct blk_zone),
 			       GFP_KERNEL | __GFP_ZERO);