From patchwork Thu Oct 8 21:39:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 7355751 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 245B69F4DC for ; Thu, 8 Oct 2015 21:44:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 507A9205E2 for ; Thu, 8 Oct 2015 21:43:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C4D22043C for ; Thu, 8 Oct 2015 21:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965173AbbJHVnn (ORCPT ); Thu, 8 Oct 2015 17:43:43 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:27605 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933428AbbJHVkQ (ORCPT ); Thu, 8 Oct 2015 17:40:16 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t98Le2MQ002818 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 8 Oct 2015 21:40:03 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t98Le2bi002151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 8 Oct 2015 21:40:02 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t98Le2hZ015869; Thu, 8 Oct 2015 21:40:02 GMT Received: from linux-siqj.site (/10.132.127.48) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 08 Oct 2015 14:40:01 -0700 From: Yinghai Lu To: Bjorn Helgaas , David Miller , Benjamin Herrenschmidt , Wei Yang , TJ , Yijing Wang , Khalid Aziz Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v7 41/60] PCI: Skip required+optional if there is no optional Date: Thu, 8 Oct 2015 14:39:00 -0700 Message-Id: <1444340359-8011-42-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1444340359-8011-1-git-send-email-yinghai@kernel.org> References: <1444340359-8011-1-git-send-email-yinghai@kernel.org> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 c49bfde..5143ea2 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -450,6 +450,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) { @@ -481,16 +499,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: @@ -578,7 +604,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;