Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1120089pxb; Fri, 20 Nov 2020 01:24:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSvSPZC40YLV5netiZ8jLxoT/QLna7rWwg6Cjv3vjuYe+8XDdEgBIp586AimsoPM8hRTYM X-Received: by 2002:a17:906:2602:: with SMTP id h2mr27778506ejc.358.1605864297269; Fri, 20 Nov 2020 01:24:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605864297; cv=none; d=google.com; s=arc-20160816; b=YzE9AhTUyIFHKTU9UxooDxg4TaxynBfs6/XsePb26ECFHGLEuQBbqf8YjNQQ648SC0 ALMRjwfpG/YHcK6tAybau7x5MOfxmQiPxgHW6dbEwFZvrl34cpQALNcAWHtFAHjZPJQM HufZ2hELh9yK/Dd6sXS+xUuQLUgZrbNCrUAJ2wRefyXc/1psl+l7rXy75Aib2fyscTgZ rrELczEaJPzMFas6KZTzu5mqDXUTVwWSLHk0O/lFql9Qxd/JVJBn5n9OPU302Mi1bWj/ FuDgJbSTurGTps6XlEH7vQbu60EKy6cPKMbMN4w0neMd+3gvSCZ0slePyGqQRe9Kymd0 m4ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ZWYdfgUMG0mlon/lsp/dLU9Vokj6XDewJlglSM89p+Q=; b=VS6/65N+PmQ8bMzQoOeoEDDm+mK/FDm3OsHxnYZwEYbnwjqVBAM9N6fpbXA8n5DKvz eSJwi/a3+Sf7RwFnjXOasaRfgQ3IOJsCuQ68EHgDxe73VVijQRNnTT1VKZO7Y8zg1ki3 knS8vqw/v75GORVbhzu/bB5q50Gto66OIn6m/FhIO7a9mjQA67Cq5DOSyy7FrPGou20/ HgUWdjUu4Vj+6VkqpibpYV+flBeaF8foguuXrntAGH2zTUk1J0kIytrdBwSYRaTbsAdN ET1HXab+e8v6fLNxf4kot/xDwX6vbsXNAS4E8LrHXkRxLMLzuxli7wdbxnyg2mDwl6JI bvZw== 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 cd11si1393087ejb.245.2020.11.20.01.24.35; Fri, 20 Nov 2020 01:24:57 -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 S1727133AbgKTJXL (ORCPT + 99 others); Fri, 20 Nov 2020 04:23:11 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7714 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbgKTJXL (ORCPT ); Fri, 20 Nov 2020 04:23:11 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CcrgC0fZDzkc9w; Fri, 20 Nov 2020 17:22:47 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.176.144) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Fri, 20 Nov 2020 17:22:57 +0800 From: Zhen Lei To: Dan Williams , Vishal Verma , Dave Jiang , linux-nvdimm , linux-kernel CC: Zhen Lei Subject: [PATCH 1/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range() Date: Fri, 20 Nov 2020 17:22:51 +0800 Message-ID: <20201120092251.2197-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.176.144] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } 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) -- 2.26.0.106.g9fadedd