From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 86BEBAAD9 for ; Thu, 15 Mar 2018 18:50:26 +0100 (CET) Received: by mail-wm0-f65.google.com with SMTP id t3so12031251wmc.2 for ; Thu, 15 Mar 2018 10:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=syXrSa9YC1OOkH9j4QYjWDBXqn/SgOQQsLC8njyCSyo=; b=h5BOBqqCRnt5wdDx34DNt9a9WHVxzChrxi/bvZp+HPSPj8d1rw1q/QRxPghy9cJfYP Bq9OE4baFS/Pj2/tv/olzcxT/N0OYrCKKBblDCVRumlE1UsCtoTCRc+of1MaoxOPVXoC VoFXSrbzrus+ALAjftBcrh30CKHdOTRiJx00LJv+cXJZYeWnCGh2tCKP1ISTziFbL5j9 0CxAYFhFE4Wls1K94DAE10PAuHZV7xfBXZlBi2xQE2KXAFdOdgFmhjGIOacKNLPkVf2A r3bqU2V5q3HkVkTzP9BgFcEzjRHmGy3quzDa84rugircCpaxkVb1TrKjm6x9k1tetlvl Fy0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=syXrSa9YC1OOkH9j4QYjWDBXqn/SgOQQsLC8njyCSyo=; b=LT9VQwSgIsUQ2694F53S0SIfUifuUaS3nUF+uGF7iT+8+ciKXIyn+CzqbYkDNulPc8 PwlI3G1yLAqN7KQ9SLHCAvuh7zIqpNVtndS+vFYZoOEAQ9jj3a2a4GoPw7ruQ15NlHEt elcFKo8uQVARXHVyaAMFNqE41mkPUNusZzM6eqkenFeEdqLqc25Sf0IOVJH4SQOfjzIF fr55j2ycIOep37YEqbJaWUqDXCEjXqhfFAY2Ywzz2RmQv1+gW+8EjKvK5mmNbRbwnfTb pkPvCaMpgExWbrwyomjjdUhHR6lCutokyvrZOjpAooW02q+vml8geXyq9FQoqfLx+x6c 1h4Q== X-Gm-Message-State: AElRT7Hqjplui+8fMs2rXjJbuYE21eorFiFOPMo90uIzul10Xz5up+T6 Lz3ykaoq3kZ5pMYLFTUlcYSufEyg X-Google-Smtp-Source: AG47ELtUgad8LkVkuWO0V8z9oMXJzBTiy5yYJMrlbWuQSu8oLqTg9wiKgZOa5mvJmrBbGnXL0rRKGA== X-Received: by 10.28.105.65 with SMTP id e62mr5370996wmc.126.1521136225739; Thu, 15 Mar 2018 10:50:25 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id 69sm4756596wmp.36.2018.03.15.10.50.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 10:50:24 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , stable@dpdk.org Date: Thu, 15 Mar 2018 18:49:42 +0100 Message-Id: <99e97172b8d33def42cc5923858a799a9fc93864.1521124599.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 12/18] bus/pci: fix find device implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Mar 2018 17:50:28 -0000 If start is set, and a device before it matches the data passed for comparison, then this first device is returned. This produces potentially infinite loops. Fixes: c7fe1eea8a74 ("bus: simplify finding starting point") Cc: stable@dpdk.org Signed-off-by: Gaetan Rivet --- drivers/bus/pci/pci_common.c | 21 ++++++++++++--------- drivers/bus/pci/rte_bus_pci.h | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 2a00f365a..2c45f8151 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -459,17 +459,20 @@ static struct rte_device * pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void *data) { - struct rte_pci_device *dev; + const struct rte_pci_device *pstart; + struct rte_pci_device *pdev; - FOREACH_DEVICE_ON_PCIBUS(dev) { - if (start && &dev->device == start) { - start = NULL; /* starting point found */ - continue; - } - if (cmp(&dev->device, data) == 0) - return &dev->device; + if (start != NULL) { + pstart = RTE_DEV_TO_PCI_CONST(start); + pdev = TAILQ_NEXT(pstart, next); + } else { + pdev = TAILQ_FIRST(&rte_pci_bus.device_list); + } + while (pdev != NULL) { + if (cmp(&pdev->device, data) == 0) + return &pdev->device; + pdev = TAILQ_NEXT(pdev, next); } - return NULL; } diff --git a/drivers/bus/pci/rte_bus_pci.h b/drivers/bus/pci/rte_bus_pci.h index 357afb912..458e6d076 100644 --- a/drivers/bus/pci/rte_bus_pci.h +++ b/drivers/bus/pci/rte_bus_pci.h @@ -74,6 +74,9 @@ struct rte_pci_device { */ #define RTE_DEV_TO_PCI(ptr) container_of(ptr, struct rte_pci_device, device) +#define RTE_DEV_TO_PCI_CONST(ptr) \ + container_of(ptr, const struct rte_pci_device, device) + #define RTE_ETH_DEV_TO_PCI(eth_dev) RTE_DEV_TO_PCI((eth_dev)->device) /** Any PCI device identifier (vendor, device, ...) */ -- 2.11.0