From patchwork Thu Oct 11 07:09:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10636173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA56069B1 for ; Thu, 11 Oct 2018 07:10:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D33CF2AE79 for ; Thu, 11 Oct 2018 07:10:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C768F2AEDA; Thu, 11 Oct 2018 07:10:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8327A2AE79 for ; Thu, 11 Oct 2018 07:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbeJKOf6 (ORCPT ); Thu, 11 Oct 2018 10:35:58 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:12787 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbeJKOf5 (ORCPT ); Thu, 11 Oct 2018 10:35:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1539241802; x=1570777802; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=TO9/d2tST9vnaD05TIZjJa0QPE0wX3n1RaGQVyoHWb4=; b=OHYvGkPMWyAbD0ZbhTcMDdk5srYQR3c4Hy7pXo4bCjQwVnRwgulYK3Ft 2vM4M4JTSY4Cr3G5bQIxsM5fq9NAIyIfb2lq/mfDhPxt7y2xo/uJId8MR wvnZxRv5EpX8w6gu7IukBnpiE5gxxIL/B52TAteSesB3Z0tT0XRhVqf05 j8St6feTo1ey+ljiF6MZ74+ES6BcYHGMumI4aWVbUpSs0rhYrVLo+2+ZY vlohg4CCRN4eDt6TBubdwvA8ydaoB2rVTLL6qM+5eMLOyCmDk5ktrWAah CdfvkUkVkRAr95YZ6fUf/JKN/5jHUn7q8PfmQmr3hM/TZDHeTcBg1WDjf Q==; X-IronPort-AV: E=Sophos;i="5.54,367,1534780800"; d="scan'208";a="196047567" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Oct 2018 15:10:01 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 10 Oct 2018 23:55:00 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Oct 2018 00:10:01 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Christoph Hellwig , Matias Bjorling Subject: [PATCH v2 05/11] block: Limit allocation of zone descriptors for report zones Date: Thu, 11 Oct 2018 16:09:46 +0900 Message-Id: <20181011070952.13248-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181011070952.13248-1-damien.lemoal@wdc.com> References: <20181011070952.13248-1-damien.lemoal@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Christoph Hellwig --- block/blk-zoned.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 32e377f755d8..bb4ed69f917f 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -355,8 +355,7 @@ 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; + rep.nr_zones = min(blkdev_nr_zones(bdev), rep.nr_zones); zones = kvmalloc_array(rep.nr_zones, sizeof(struct blk_zone), GFP_KERNEL | __GFP_ZERO);