Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1842083pxu; Thu, 17 Dec 2020 22:11:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvQWzoDTSR5TBLY0mpTFIfC8O5lZG2VoDJGBjhYiY9mEbfGNMq91X7vqpkBcYgujMj2dby X-Received: by 2002:a50:c3c5:: with SMTP id i5mr2842328edf.166.1608271871308; Thu, 17 Dec 2020 22:11:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608271871; cv=none; d=google.com; s=arc-20160816; b=zAdI7K2JyYXS/0W+NEvX7YZgXMWk/770tbplvPOAyJMRTctGHxw0w7qEl12YTkT6zw 1Q3JJBpgC0R6XavBnsD8iPDwud9Z/8SrBS1rmXvbnmgZ06HXP+8BIIg7EJPTKlYzusWM wvEUZeJSumy8cfuIl0+jePCsqxgTOC13h5avbQ34wyq+3ENw3So1rpgdD40Mnr4OAaDO QHor487ai5qA1UTqL2w+ikQsVcOcQSoKyljeGrBiIGpwrwPQDihlEstrTse3Xfu0Dxsk IPjjGZ2oWb48j0Krlyij844buBz9HPeK5K4YM5T9iPmorhqcT88naYezdJ4mv0T7xNCz lf7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject; bh=DXmZvr6Q4/iZQsdRJtmL4GU+GE+Id+eD0L+//2wy/KE=; b=pFTN48ElNmyy3kvHrXBWNtOvPl2Can3zld3gnyhhiWpu5jRxGX8uf0UTplALKLxgsk 7mkV3tz0T6AuyylbeK9QygsoX2G2VEQo8aPEQhYAw/4p1P1goX0Y3YhYsOevN1HIx9ib w8XQKqoO7dCXRHRcN1QXfl1A7HffV7nz1IsFP/rXCuzyOMLHYttBspqpcGoKXQh+EsuY vVvJE3ijEs0Gcd2AaOU+jbZ8pwr0aGM1LGNeU0+GKrNk6QDXL3leNDdIwKbo2pnsMjED ZZt8gvAHSUQUKmYkOhGNaiz4bJnvazHgxyMyS7LpGOp1v7A40374sATNE3bsKKV7mVnd oI+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si5292929edk.605.2020.12.17.22.10.47; Thu, 17 Dec 2020 22:11:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732590AbgLRGKC (ORCPT + 99 others); Fri, 18 Dec 2020 01:10:02 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:9226 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725298AbgLRGKB (ORCPT ); Fri, 18 Dec 2020 01:10:01 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Cxz236Fl7zksDZ; Fri, 18 Dec 2020 14:08:27 +0800 (CST) Received: from [127.0.0.1] (10.174.177.9) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Fri, 18 Dec 2020 14:09:16 +0800 Subject: Re: [PATCH 1/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range() To: Dan Williams , Vishal Verma , Dave Jiang , linux-nvdimm , linux-kernel References: <20201120092251.2197-1-thunder.leizhen@huawei.com> From: "Leizhen (ThunderTown)" Message-ID: <55970773-35ff-1afb-940b-8342b09aea9a@huawei.com> Date: Fri, 18 Dec 2020 14:09:15 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20201120092251.2197-1-thunder.leizhen@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.9] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/11/20 17:22, Zhen Lei wrote: > Swap the calling sequence of krealloc() and __request_region(), call the > latter first. In this way, the value of dev_dax->nr_range does not need to > be considered when __request_region() failed. > > Signed-off-by: Zhen Lei > --- > drivers/dax/bus.c | 29 ++++++++++++----------------- > 1 file changed, 12 insertions(+), 17 deletions(-) > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > index 27513d311242..1efae11d947a 100644 > --- a/drivers/dax/bus.c > +++ b/drivers/dax/bus.c > @@ -763,23 +763,15 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, > return 0; > } > > - ranges = krealloc(dev_dax->ranges, sizeof(*ranges) > - * (dev_dax->nr_range + 1), GFP_KERNEL); > - if (!ranges) > - return -ENOMEM; > - > alloc = __request_region(res, start, size, dev_name(dev), 0); > - if (!alloc) { > - /* > - * If this was an empty set of ranges nothing else > - * will release @ranges, so do it now. > - */ > - if (!dev_dax->nr_range) { > - kfree(ranges); > - ranges = NULL; > - } > - dev_dax->ranges = ranges; > + if (!alloc) > return -ENOMEM; > + > + ranges = krealloc(dev_dax->ranges, sizeof(*ranges) > + * (dev_dax->nr_range + 1), GFP_KERNEL); > + if (!ranges) { > + rc = -ENOMEM; > + goto err; Hi, Dan Williams: In fact, after adding the new helper dev_dax_trim_range(), we can directly call __release_region() and return error code at here. Replace goto. > } > > for (i = 0; i < dev_dax->nr_range; i++) > @@ -808,11 +800,14 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, > dev_dbg(dev, "delete range[%d]: %pa:%pa\n", dev_dax->nr_range - 1, > &alloc->start, &alloc->end); > dev_dax->nr_range--; > - __release_region(res, alloc->start, resource_size(alloc)); > - return rc; > + goto err; > } > > return 0; > + > +err: > + __release_region(res, alloc->start, resource_size(alloc)); > + return rc; > } > > static int adjust_dev_dax_range(struct dev_dax *dev_dax, struct resource *res, resource_size_t size) >