From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id CA6F7A48D for ; Fri, 27 Apr 2018 16:15:55 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id o15-v6so1934738wro.11 for ; Fri, 27 Apr 2018 07:15:55 -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=us76fQdRiUP4nPV/qm6TYRh7X2VN3qJdaEmU2mB4cko=; b=KtOMALlOxnX1m6ptx8KNsovydSwAYUtKDQmYBKYt6ulfnuZSqceUCRzXRMzYQOJTbg aSFumrbxLR12hes3k/PnZp3xySb6+ehsnRKj8xpC4IW7OwK2uQr9e+rR0M+T1cyXxWaJ b7+ism5tQ5DFDqxTMfMMchp3KyRAlPdV8eGkcLK769O9v8VjJU8M4LiNPiDyl3UneqYQ gGYipL1IFQw8aYbvhDLCk1MSwp0OdqKhwATNJWi57K5NmLJ6mBGsCojvtGeLmZPQPgRO wN8MmV+XO/Z71VKL1XfKmXLrvgMt3J59z+MhI4nH12S5dkB5ebRuyW2i8HqvscJXYxU7 1hVQ== 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=us76fQdRiUP4nPV/qm6TYRh7X2VN3qJdaEmU2mB4cko=; b=Me+miQQNf/saFyROM+onY0M4Ry7nALuWwCxCzjEymGP7ffS7+LihVt5UV8+7EDX9we gLAAdhky3SaMGf5x+vb6HZAo0jeVuhPGP2hxC7N+jsdA8M5lvz+o9RnkHmeOGgVVpOIU vgABFBSDTghl1H76BBKCGx2ajzWBK3MUCxrFXZJqCuZ1UlwkRQRzQ3uNE6shJdMgbbWo YU2tiS7ouJYsJGRUZvxKpGVvu0Tttj0yLWoDWJhjunfXJYNHOBOyqyPczMNyKMXzIv54 IqrbfrJVxGBv0GVr6EnV2oEtFybveyPknbxQumNBEJxyDAfRuqEyfAmlkQ6X1+0lpbSC qtlw== X-Gm-Message-State: ALQs6tAc/kYTQtTD1/MNtDORNPL41EPyl1aBDbPhfj8NFp3Efuhsj4vp qDXKS5gcMmsMTJmRSv4tVQ93QCxF X-Google-Smtp-Source: AB8JxZqowFUOCYzc14J0X+TjcA35jhMsDRExHMSa8Fr6QsbTtb6Vzyoqn4ko/KUKsttyXok8dPGpOA== X-Received: by 2002:adf:a294:: with SMTP id s20-v6mr1901095wra.114.1524838555183; Fri, 27 Apr 2018 07:15:55 -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 b10-v6sm3297374wrn.42.2018.04.27.07.15.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 07:15:54 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , stable@dpdk.org Date: Fri, 27 Apr 2018 16:13:06 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 2/2] 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, 27 Apr 2018 14:15:56 -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 84fa51f98..9f576eb80 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -495,16 +495,20 @@ 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; rte_spinlock_lock(&vdev_device_list_lock); - 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) break; + dev = TAILQ_NEXT(dev, next); } rte_spinlock_unlock(&vdev_device_list_lock); -- 2.11.0