From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by dpdk.org (Postfix) with ESMTP id C88721BAD8 for ; Wed, 11 Apr 2018 02:04:56 +0200 (CEST) Received: by mail-wr0-f194.google.com with SMTP id u46so30145wrc.11 for ; Tue, 10 Apr 2018 17:04:56 -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=hHJ8sn4V93fsnIoLNZ5mLkzH09KvRw5mj9tfIPqJJKNtx7QoH78KjXm6Ks+gGByJFk spEfIF+hyoRl+WoYu03CHvIpxJJNbVNxfjDw9tBxiDaH1OXLUZzEaaJB4284hHBkeka7 gLy7xQ5thRnGwmJyc/9b0oT+uTGV1mhL1m27XLdgCUCH/+N1Ee6D5qCsEAkyRuRUbFFs ot7rYAQwuzKP37jmvQrFrjTQIDDwWViyJhgU6U9r4S+vHC0pI5aAgOZ5OBz9SIid3/Jq ISsRG24h/VuI711Jmp0M3b70jJ/Fl+EqBoNeEmX0Hyc8ju/XcrsqquWBRdCLMTg3TK0/ Nxnw== 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=PS5x/kTCkxQDmTFrIQUd0KI4WLjYA6ekA5IJKN8hZUgVi9tLfplPm9qoV7Zg0HBpR6 ZrF/j/G9GU51hjctD60S165tzlgc+C4q564dyYtflyPL0Fc2DIINiyZH8bCu8VP2Hos1 Hf4HMxRoqzbovTN3fCIe3WmPiGRH6u/DhD07cxGpKjX+caDmWEKjr/ers3bA0TaLeExj gyk1fx76U6aDZfl0M/85OYrYEytmpuGV7N1N1fiUD17uLoLn3BEL7xjA8M+YmEOZdSAB Qzpyfh7wbBjKzui5muWkJi0r9EgHMQVJxEbULkBkROgMkMxpDuEJPZRs+bLeZz1k5qt0 7O6A== X-Gm-Message-State: ALQs6tD0lD1M0g1Vvj8SVFf09KjYgXTA54M4vseKjuOcRq5A/Z4dMfDz i9hiQMC0UJ8IxQQK3EsYbVom0cyI X-Google-Smtp-Source: AIpwx4/ELMBaRjpshBnydgXZGmq/vZImd3fQjet1jayi/RdJLx73X79oNjuaxLqmM8PPSjHbmXlVqA== X-Received: by 10.223.138.138 with SMTP id y10mr1606199wry.44.1523405096114; Tue, 10 Apr 2018 17:04:56 -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 39sm7626563wry.89.2018.04.10.17.04.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 17:04:55 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , stable@dpdk.org Date: Wed, 11 Apr 2018 02:04:13 +0200 Message-Id: <7f268a74f810f50e4451c1f0dbea656baa861e4c.1523404469.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 v5 12/21] 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: Wed, 11 Apr 2018 00:04:57 -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