From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id 3AA7E3772 for ; Mon, 25 Jul 2016 21:54:47 +0200 (CEST) Received: by mail-wm0-f52.google.com with SMTP id f65so148281348wmi.0 for ; Mon, 25 Jul 2016 12:54:47 -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; bh=Vyep2dnlDzaNX8l8vrUF7fyI7985eDLXCD7aka1BU98=; b=0RurQD1QdLDupUg0EUK7mVzGmRkeTxLCSYmk7DWfrprqppNQDTHAgd2ZBzlOStkO1X KjUTDz2uB3Syp0XEjvTmBqbcMIrLWZT5Af58/GIdMjGAj8nGaS7IFFpAvuWG5T1lUV6F w5WSXP2h1E48xcHbxUoI5pH6zJpSCY4ymN4fnMsWjus21TJq4na0P1HYrbq72Op3SrkO H/CrHTIwp3P4ThRbi0436JQ/T5loxe/zgd8lhE1wElWfgTRSgk3p+uDMPjb/bkLSm20l kOrnVrlLGHkOsL1pIvwYOVVu0zC8wZzStzacjVvD3rLNWvHV0uc2r7MBp/k2zGN+Qoz4 1jwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Vyep2dnlDzaNX8l8vrUF7fyI7985eDLXCD7aka1BU98=; b=gnVCS/bZ9euqpSxkqyIMSIoqeWKGa0gJ32Ud8O/IACjc8qWT/6z78IDPDpCk//lEzz JWXn8IexvP/lGxWHMvoHURIfDeS3WvtkqvR6hh5pde7ZyokO77bCfdyTFDYRC8tm1+3d tKXQfFxH4s4X/wqnW4k3YXI4+VgJu5FirNzKaTjMHCVWkLV/U1DuFZyL8ej3iXikskcz TcFF8oW2fmIB13gqiIW9+Dnga2ktRuCJwbLBWeh+Hs2WD1xsyi4RT0e55lTuvNcMJe9p g3Nswai/iQs8pbuV8fip55iqPRmwCMuQiTq468h2PpM8hU6d9weQzfBEmkZXCfYY108F /JdA== X-Gm-Message-State: ALyK8tKc1cqPH4AYHDLKjzQDtdTuat9LfeZ8+V+/qcrYOtRGn3daZp3OTBqeVMT9e8I+oJ6/ X-Received: by 10.28.22.70 with SMTP id 67mr44162059wmw.52.1469476485938; Mon, 25 Jul 2016 12:54:45 -0700 (PDT) Received: from XPS13.localdomain (184.203.134.77.rev.sfr.net. [77.134.203.184]) by smtp.gmail.com with ESMTPSA id v189sm28925247wmv.12.2016.07.25.12.54.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Jul 2016 12:54:44 -0700 (PDT) From: Thomas Monjalon To: olivier.matz@dpdk.org Cc: dev@dpdk.org Date: Mon, 25 Jul 2016 21:54:36 +0200 Message-Id: <1469476476-2148-1-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2] mempool: fix unsafe removal from list by callback X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2016 19:54:47 -0000 If a mempool is removed from the list by a callback function during rte_mempool_walk(), the TAILQ_FOREACH loop will fail unexpectedly. It is fixed by using the safe version of the loop macro. Reported-by: Sergio Gonzalez Monroy Signed-off-by: Thomas Monjalon --- lib/librte_mempool/rte_mempool.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 8806633..2e28e2e 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -1283,12 +1283,13 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), { struct rte_tailq_entry *te = NULL; struct rte_mempool_list *mempool_list; + void *tmp_te; mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list); rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK); - TAILQ_FOREACH(te, mempool_list, next) { + TAILQ_FOREACH_SAFE(te, mempool_list, next, tmp_te) { (*func)((struct rte_mempool *) te->data, arg); } -- 2.7.0