From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 5A74A1BB96 for ; Fri, 13 Apr 2018 15:23:14 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id r82so4210031wme.0 for ; Fri, 13 Apr 2018 06:23:14 -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=/eyQ2v0oXHedW7lyFQR0H1RCpUBqJoevhVBtnUxXgNY=; b=Ydw++Y7gxKZZJVPpLvmguyw2iN9HiNrC8DifRpgqz1VKMlsh3o5ofIuP6TLvA3zTpE jjr6Co1VtrzdmTzHUQKAO4KgmOlENrXpsTFT8m7pX1t2dQo/LYsSuU4S5pAVD1Kh9v4A OcuEzwi05FLjFQPX4/DbxA7JSDt7AJGpMksFt4dcxKh9oSzXKJ9oiaEnlft3Pq3okidD CGF7gO/DzsEsoTszggTywjtwE7ztdCZ0+Mvbh5+rkUH9Iisw5+XtHSeNnLNjSUqpBaUf gs7jNyGLHSfYOdBVnf5GMyfsr9WDgvlJS3PudNndSBVO1dTsefhTWaShqszAkAiDGKri h84A== 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=/eyQ2v0oXHedW7lyFQR0H1RCpUBqJoevhVBtnUxXgNY=; b=KhZ5mVzblC/WXipoxDyzIbB6H+5U0k0PS2my/1/N4IWQlnQdZ/1X75QQVUKDALR1pn EOsCYEHdhuNF1vzs+wKv/TSP7c6Ao7Wkvi5UzcPChGBm/RhG+2xyj2SaO/zYDrAnvfVg 2JRbV0xY7I65V5AQUuDuF1xmqHyG8uTm0xSkcy1F+L0rfwpotrrBWRRYM8FWntuiBB6i U1lu6qINvNcA3rkT8UDERnHqAN1Gud1CewDjSRVTUQSv8Vd4gbW7Oqvb1KSgmW2ySwHn LW+gP63uGBNK/zpIArzluVg39ew2rPKxbZ3bsfloTlXisThudFBb31h64xYkup1XKkvo HXFw== X-Gm-Message-State: ALQs6tBDUHvY1Idf8wooyZ1HvqCbtl+5IdcqEvjI8y9aUbZsZCc03vX6 3sgwPPOv36WDqFbgcsj5/B+gX4S/ X-Google-Smtp-Source: AIpwx4873+EMoeAXysDWX/8scYGeWlbH52Fcpk4p/D9doQnfXHCcRYHxnOxB+NHnEg03plXKAAx7kg== X-Received: by 10.28.71.157 with SMTP id m29mr3444411wmi.106.1523625793702; Fri, 13 Apr 2018 06:23:13 -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 r200sm2377244wmb.9.2018.04.13.06.23.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Apr 2018 06:23:12 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , stable@dpdk.org Date: Fri, 13 Apr 2018 15:22:28 +0200 Message-Id: <9f58c9485c5de859beb1754fc9b3536030cd1b05.1523625525.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 v6 13/22] 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: Fri, 13 Apr 2018 13:23:14 -0000 If start is set, and a device before it matches the data passed for comparison, then this first device is returned. This induces 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