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 324F01C18A for ; Fri, 13 Apr 2018 15:23:18 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id t67so5243087wmt.0 for ; Fri, 13 Apr 2018 06:23:18 -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=1vBV+BP282H03Lm5BCzbXZLdoE51GH0ER4zzSWrfePA=; b=2SEE6JSmvn+oNTUSqUQ5b3pvlzzqyPlKk02o1gmPWl80Yf1S8XamlPE56mmYBCU4CX 7rvSYKIcv12g7NWTv2bfrUyKfUJa5vLK4oWGhmYDU42iboHg7nV/Sh3iKb3hNmbNJR2P d/qf37VXQ3j1v4/VOjeRVWB2/vDffriwpSxaMRM0aCL3Gju+zquOQu590GPAgHKwHWQs SlLQck8Eo4xN9DNbf4Y4YUNF8SjPdxBFrnZNhapc68MYEgWoN6uEqRScRM7r77zRzQML kU5jBkrqeoE0BSlnphd3mK54iZt6jJy2n+piJvPYY0FwJ8tAPqUOQXDf6FPaPM3tPbXJ 7OkA== 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=1vBV+BP282H03Lm5BCzbXZLdoE51GH0ER4zzSWrfePA=; b=RxzeqNtVqgTQNWPVmQ3esrfX8tKJi1Lt0JelCdafp2LNDy45M/IgZE/b7MLVPTey5E JhpaJR7RwBz6fWsDPHvQcYo8/9thi8p6F4ns7TXsTFKY+ZRke/9WvEX82QbfKEjype3m fgGVvkzbrOiHjBrsp1sIUXbkvpxGI3c4+G9RuSXB22T72+6gVp9aI+u1s4w2s6htvXZF L3vgai/vDsMfWlqAVV/Pi4SSlzaDzwLGG/Uwb/PdyeDuNMgFWpGVa4VkT1PuUe1zAmZz sUalM2d2ajWdJtD1yDXEUhaEOe0LAA8X3FtWHeJJBMRcO67s8XOagIYa91lThDM+JTOp h31A== X-Gm-Message-State: ALQs6tDVLpjovg7+sCkqNbawRQN9m5ybtJqYLem1amloI1rzqRjnt26t iZAQKsD56g20EJEyESwVyuljzw6w X-Google-Smtp-Source: AIpwx4/s3VwuIKBYZ4pOmOn/WF6UrdJk0V37uMVtHJS+JoLSIjz0CvY08FwR7SUelMnxASbbjXoVwg== X-Received: by 10.28.143.199 with SMTP id r190mr3449488wmd.132.1523625797507; Fri, 13 Apr 2018 06:23:17 -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.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Apr 2018 06:23:16 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , stable@dpdk.org Date: Fri, 13 Apr 2018 15:22:31 +0200 Message-Id: <5579b2f2895eed8693bdcd5c6c90c8d2af77658c.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 16/22] bus/vdev: 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:18 -0000 If start is set and a device before it matches the data, this 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/vdev/rte_bus_vdev.h | 3 +++ drivers/bus/vdev/vdev.c | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/bus/vdev/rte_bus_vdev.h b/drivers/bus/vdev/rte_bus_vdev.h index 646d6c090..f9b5eb596 100644 --- a/drivers/bus/vdev/rte_bus_vdev.h +++ b/drivers/bus/vdev/rte_bus_vdev.h @@ -25,6 +25,9 @@ struct rte_vdev_device { #define RTE_DEV_TO_VDEV(ptr) \ container_of(ptr, struct rte_vdev_device, device) +#define RTE_DEV_TO_VDEV_CONST(ptr) \ + container_of(ptr, const struct rte_vdev_device, device) + static inline const char * rte_vdev_device_name(const struct rte_vdev_device *dev) { diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index f8dd1f5e6..c135554c0 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -358,15 +358,19 @@ static struct rte_device * vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void *data) { + const struct rte_vdev_device *vstart; struct rte_vdev_device *dev; - TAILQ_FOREACH(dev, &vdev_device_list, next) { - if (start && &dev->device == start) { - start = NULL; - continue; - } + if (start != NULL) { + vstart = RTE_DEV_TO_VDEV_CONST(start); + dev = TAILQ_NEXT(vstart, next); + } else { + dev = TAILQ_FIRST(&vdev_device_list); + } + while (dev != NULL) { if (cmp(&dev->device, data) == 0) return &dev->device; + dev = TAILQ_NEXT(dev, next); } return NULL; } -- 2.11.0