Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932832AbcDHAYp (ORCPT ); Thu, 7 Apr 2016 20:24:45 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:36633 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932680AbcDHAW2 (ORCPT ); Thu, 7 Apr 2016 20:22:28 -0400 From: Yinghai Lu To: Bjorn Helgaas , David Miller , Benjamin Herrenschmidt , Linus Torvalds Cc: Wei Yang , TJ , Yijing Wang , Khalid Aziz , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v11 42/60] PCI: Skip required+optional if there is no optional Date: Thu, 7 Apr 2016 17:15:55 -0700 Message-Id: <1460074573-7481-43-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1460074573-7481-1-git-send-email-yinghai@kernel.org> References: <1460074573-7481-1-git-send-email-yinghai@kernel.org> X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2312 Lines: 79 If the bridge does not support hotplug and has no child with sriov support, We will not have optional resources. We could get out early and don't try required+optional allocation. Also in the loop that update res with optional add info, skip resource that add_size is 0. Signed-off-by: Yinghai Lu --- drivers/pci/setup-bus.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index a4f53ec..373f76f 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -449,6 +449,24 @@ static bool pci_need_to_release(unsigned long mask, struct resource *res) return false; /* should not get here */ } +static bool has_addon(struct list_head *head, + struct list_head *realloc_head) +{ + int add_count = 0; + struct pci_dev_resource *dev_res, *tmp_res; + + /* check if we have add really */ + list_for_each_entry(dev_res, head, list) { + tmp_res = res_to_dev_res(realloc_head, dev_res->res); + if (!tmp_res || !tmp_res->add_size) + continue; + + add_count++; + } + + return add_count != 0; +} + static bool save_resources(struct list_head *head, struct list_head *save_head) { @@ -480,16 +498,24 @@ static bool __assign_resources_required_optional_sorted(struct list_head *head, struct pci_dev_resource *save_res; struct pci_dev_resource *dev_res, *tmp_res; unsigned long fail_type; - resource_size_t add_align; + resource_size_t add_align, add_size; struct resource *res; + if (!has_addon(head, realloc_head)) + return false; + if (!save_resources(head, &save_head)) return false; /* Update res in head list with add_size in realloc_head list */ list_for_each_entry(dev_res, head, list) { res = dev_res->res; - res->end += get_res_add_size(realloc_head, res); + add_size = get_res_add_size(realloc_head, res); + + if (!add_size) + continue; + + res->end += add_size; /* * There are two kinds of additional resources in the list: @@ -577,7 +603,7 @@ static void __assign_resources_sorted(struct list_head *head, */ /* Check required+optional add */ - if (realloc_head && !list_empty(realloc_head) && + if (realloc_head && __assign_resources_required_optional_sorted(head, realloc_head)) return; -- 1.8.4.5