From patchwork Fri Oct 12 10:08:44 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: 10638323 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 7C2C317E3 for ; Fri, 12 Oct 2018 10:09:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D23C2B841 for ; Fri, 12 Oct 2018 10:09:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61D092B846; Fri, 12 Oct 2018 10:09:01 +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 195942B845 for ; Fri, 12 Oct 2018 10:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728400AbeJLRkj (ORCPT ); Fri, 12 Oct 2018 13:40:39 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:63720 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728346AbeJLRki (ORCPT ); Fri, 12 Oct 2018 13:40:38 -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=1539338940; x=1570874940; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Lp9TVuHV1+oQ0OmD15xSqaQAv9fEEA8NPm3I+/4r4VQ=; b=P+dDxuAeLU4vFlO/oS7OvQpc0m9WA+umFe0SYPq3fLyfI7OiY/UVVIrt NDFzatchEAR/es7/uNwbz0zw/zjZypdBJGA0cfBtVxDvLVP7ehrwc4I2v 43a0e/fdMDr6XS9d0d+30g1xQ7sIfdYTKLXg0MIXTSTimkoCRXBCS/Khk Op08yhUeVaRRpDKNCq09mJPG3kfGumc7ulmwXSRfLoU1kIBKkjJYUYHNh bM2OlqgcIG82+URyWywfOFqJUGP+MCW0ArJRMa1XBmFlaRbzZhLH+BzQr tb9utTPAtZrEcljdHt9RTjpELWZWZ3+leZWBN4I88hiTcNiRIQckFeFjc A==; X-IronPort-AV: E=Sophos;i="5.54,371,1534780800"; d="scan'208";a="96419686" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2018 18:08:59 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 12 Oct 2018 02:54:19 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Oct 2018 03:08:59 -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 v4 05/11] block: Limit allocation of zone descriptors for report zones Date: Fri, 12 Oct 2018 19:08:44 +0900 Message-Id: <20181012100850.23316-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012100850.23316-1-damien.lemoal@wdc.com> References: <20181012100850.23316-1-damien.lemoal@wdc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 Reviewed-by: Hannes Reinecke --- 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);