From patchwork Mon Jan 24 10:34:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583376 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IxSkuQ2w; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5wZ1x0mz9t0k for ; Mon, 24 Jan 2022 21:35:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4CE5C83EFB; Mon, 24 Jan 2022 10:35:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mrHM7D_x90u6; Mon, 24 Jan 2022 10:35:21 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 51CA983EA3; Mon, 24 Jan 2022 10:35:20 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 112B1C0072; Mon, 24 Jan 2022 10:35:20 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 259F6C002F for ; Mon, 24 Jan 2022 10:35:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id B5C9982F99 for ; Mon, 24 Jan 2022 10:35:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Kz-mksGOJxoO for ; Mon, 24 Jan 2022 10:35:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id ADEFE83E52 for ; Mon, 24 Jan 2022 10:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sH0eMeLCCSy6t9gnBSNzmpdkrwitnEH3hCf+5QvEodE=; b=IxSkuQ2wba2Zvw5kyYAWV3f6l5K8Qndw6R6hN44mZxqdqmME8HFzjJ4SrtAMCvWvGWOB+g dACrIDd14gqU7RGTGDwC/v+PqCLIarg9MjEDRmkxTeXdYpkbW6kX0KTXb8h23Re+LMrjwA xlRxB6ny2/kBIuxFUKGNgRYG8NzuZ+g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-88-_Dy_lRmGPEWksdL4VPAokg-1; Mon, 24 Jan 2022 05:35:12 -0500 X-MC-Unique: _Dy_lRmGPEWksdL4VPAokg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 304C51083F65; Mon, 24 Jan 2022 10:35:11 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id C92727A238; Mon, 24 Jan 2022 10:34:59 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:33 +0100 Message-Id: <20220124103445.2459400-2-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 01/13] util: add multi-variable loop iterator macros X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Multi-variable loop iterators avoid potential undefined behavior by using an internal iterator variable to perform the iteration and only referencing the containing object (via OBJECT_CONTAINING) if the iterator has been validated via the second expression of the for statement. That way, the user can easily implement a loop that never tries to obtain the object containing NULL or stack-allocated non-contained nodes. Signed-off-by: Adrian Moreno --- include/openvswitch/util.h | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h index 228b185c3..f72438fdf 100644 --- a/include/openvswitch/util.h +++ b/include/openvswitch/util.h @@ -145,6 +145,51 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *); #define INIT_CONTAINER(OBJECT, POINTER, MEMBER) \ ((OBJECT) = NULL, ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER)) + +/* Multi-variable container iterators. + * + * The following macros facilitate safe iteration over data structures + * contained in objects. It does so by using an internal iterator variable of + * the type of the member object pointer (i.e: pointer to the data structure). + */ + +/* Multi-variable iterator variable name. + * Returns the name of the internal iterator variable. + */ +#define ITER_VAR(NAME) NAME ## __iterator__ + +/* Multi-variable initialization. Creates an internal iterator variable that + * points to the provided pointer. The type of the pointer must be that of the + * iterator variable, not the containing object. + * + * The _EXP version evaluates the given expressions once. + */ +#define INIT_MULTIVAR(VAR, MEMBER, POINTER, ...) \ + INIT_MULTIVAR_EXP(VAR, MEMBER, POINTER, (void) 0) + +#define INIT_MULTIVAR_EXP(VAR, MEMBER, POINTER, ...) \ + OVS_TYPEOF(&(VAR->MEMBER)) ITER_VAR(VAR) = ( __VA_ARGS__ , \ + ((OVS_TYPEOF(&(VAR->MEMBER))) POINTER)) + +/* Multi-variable condition. + * Evaluates the condition expression (that must be based on the internal + * iterator variable). Only if the result of expression is true, the OBJECT is + * set to the object containing the current value of the iterator variable. + * + * It is up to the caller to make sure it is safe to run OBJECT_CONTAINING on + * the pointers that verify the condition. + */ +#define CONDITION_MULTIVAR(EXPR, VAR, MEMBER) \ + ((EXPR) ? \ + (((VAR) = OBJECT_CONTAINING(ITER_VAR(VAR), VAR, MEMBER)), 1) : \ + (((VAR) = NULL), 0)) + +/* Multi-variable update. + * Evaluates the expresssion that is supposed to update the iterator variable. + */ +#define UPDATE_MULTIVAR(EXPR, VAR) \ + ((EXPR), (VAR) = NULL) + /* Returns the number of elements in ARRAY. */ #define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY) From patchwork Mon Jan 24 10:34:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y1AZBj7n; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5wb6QXSz9t0k for ; Mon, 24 Jan 2022 21:35:27 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 013A24157B; Mon, 24 Jan 2022 10:35:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NiOKzaZsYpeK; Mon, 24 Jan 2022 10:35:24 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 55935410D5; Mon, 24 Jan 2022 10:35:23 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 15285C007A; Mon, 24 Jan 2022 10:35:23 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1E658C007A for ; Mon, 24 Jan 2022 10:35:20 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 6722F83EA3 for ; Mon, 24 Jan 2022 10:35:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JEg_sHvgkCbI for ; Mon, 24 Jan 2022 10:35:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id B6F1883323 for ; Mon, 24 Jan 2022 10:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0YPAW9O36sybG4NTx1leyU/CycHzkBw2Wdcjxjpq1LY=; b=Y1AZBj7nQBXSzbOLHHzqsCjA9sRHqvTDpPc8eFMjUXCtk9kyjfE+z0AlRBvwdXsmH1/QQV tsOT6Ly7Z/SZ3ipQ7aOogL0JjaOyZRDNpQlmA9TL7k6hKW51G1Cv1TDLTKyhDxMyus+X11 D/3zzwkCVPYaYgC0XmcKIPMHxC3e/uQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-4zb9jYNQOoaRSEHrlB_T0A-1; Mon, 24 Jan 2022 05:35:14 -0500 X-MC-Unique: 4zb9jYNQOoaRSEHrlB_T0A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 93E671083F62; Mon, 24 Jan 2022 10:35:13 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93EB17A238; Mon, 24 Jan 2022 10:35:11 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:34 +0100 Message-Id: <20220124103445.2459400-3-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 02/13] util: add safe multi-variable iterators X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Safe version of multi-variable iterator helpers declare an internal variable to store the next value of the iterator temporarily. This eliminates the need to declare an external variable to store it, making loops more readable and less error prone. Signed-off-by: Adrian Moreno --- include/openvswitch/util.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h index f72438fdf..9cb70a567 100644 --- a/include/openvswitch/util.h +++ b/include/openvswitch/util.h @@ -190,6 +190,39 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *); #define UPDATE_MULTIVAR(EXPR, VAR) \ ((EXPR), (VAR) = NULL) + +/* In the safe version of the multi-variable container iteration, the next + * value of the iterator is precalculated on the condition expression. + * This allows for the iterator to be freed inside the loop. + * + * The next value of the iterator is stored in a variable declared in the + * INIT_MULTIVAR_SAFE macro and its name is ITER_NEXT_VAR(OBJECT). + */ +#define ITER_NEXT_VAR(NAME) NAME ## __iterator__next__ + +/* Safe initialization declares both iterators. */ +#define INIT_MULTIVAR_SAFE(VAR, MEMBER, POINTER) \ + INIT_MULTIVAR_SAFE_EXP(VAR, MEMBER, POINTER, (void) 0) + +#define INIT_MULTIVAR_SAFE_EXP(VAR, MEMBER, POINTER, ...) \ + OVS_TYPEOF(VAR->MEMBER) *ITER_VAR(VAR) = \ + ( __VA_ARGS__ , (OVS_TYPEOF(&(VAR->MEMBER))) POINTER), \ + *ITER_NEXT_VAR(VAR) = NULL + +/* Evaluate the condition expression and, if satisfied, update the _next_ + * iterator with the NEXT_EXPR. + * Both EXPR and NEXT_EXPR should only use ITER_VAR(VAR) and + * ITER_NEXT_VAR(VAR). + */ +#define CONDITION_MULTIVAR_SAFE(EXPR, NEXT_EXPR, VAR, MEMBER) \ + ((EXPR) ? \ + (((VAR) = OBJECT_CONTAINING(ITER_VAR(VAR), VAR, MEMBER)), \ + (NEXT_EXPR), 1) : \ + (((VAR) = NULL), 0)) + +#define UPDATE_MULTIVAR_SAFE(VAR) \ + UPDATE_MULTIVAR(ITER_VAR(VAR) = ITER_NEXT_VAR(VAR), VAR) + /* Returns the number of elements in ARRAY. */ #define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY) From patchwork Mon Jan 24 10:34:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=buvoUz4R; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5wf4QRRz9t0k for ; Mon, 24 Jan 2022 21:35:30 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id AF68B408C3; Mon, 24 Jan 2022 10:35:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OMpaaCY3pDKn; Mon, 24 Jan 2022 10:35:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 31BE540635; Mon, 24 Jan 2022 10:35:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 04378C0072; Mon, 24 Jan 2022 10:35:25 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 15469C007B for ; Mon, 24 Jan 2022 10:35:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 3782B83EE6 for ; Mon, 24 Jan 2022 10:35:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=fail (1024-bit key) reason="fail (body has been altered)" header.d=redhat.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vaXd2GNy2EQY for ; Mon, 24 Jan 2022 10:35:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8F92383EB5 for ; Mon, 24 Jan 2022 10:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5d062uz9YvWhbYvY1GVpH90ipR7jrugoBfLqq8Vv+jw=; b=buvoUz4R+cNv+v5FFme/yOqBRsX9jwWcf+A/SAHfuJADEj81Jy+SoHRMzW1JE/KmxudYle XUhiNNKZLafGiEYJURLgzFvNaUvZFQTLEn0rBsw75MsxSV8sMZJERnHdKSexL9A6hRN+y+ l+XGSXhKlLmxz8X8lcXs5npDKbskTWM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-91-WwoXs7x0N0uNhom5Z1WkAA-1; Mon, 24 Jan 2022 05:35:17 -0500 X-MC-Unique: WwoXs7x0N0uNhom5Z1WkAA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 19F563482F; Mon, 24 Jan 2022 10:35:16 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED1877A2E1; Mon, 24 Jan 2022 10:35:13 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:35 +0100 Message-Id: <20220124103445.2459400-4-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 03/13] list: use multi-variable helpers for list loops X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Use multi-variable iteration helpers to rewrite non-safe loops. There is an important behavior change compared with the previous implementation: When the loop ends normally (i.e: not via "break;"), the object pointer provided by the user is NULL. This is safer because it's not guaranteed that it would end up pointing a valid address. Clang-analyzer has successfully picked the potential null-pointer dereference on the code that triggered this change (bond.c) and nothing else has been detected. For _SAFE loops, keep the (now unused) NEXT/PREV variable to maintain backwards compatibility. Signed-off-by: Adrian Moreno --- include/openvswitch/list.h | 67 +++++++++++++++++++++----------------- ofproto/bond.c | 2 +- tests/test-list.c | 6 ++-- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/include/openvswitch/list.h b/include/openvswitch/list.h index 8ad5eeb32..263789b60 100644 --- a/include/openvswitch/list.h +++ b/include/openvswitch/list.h @@ -72,36 +72,43 @@ static inline bool ovs_list_is_empty(const struct ovs_list *); static inline bool ovs_list_is_singleton(const struct ovs_list *); static inline bool ovs_list_is_short(const struct ovs_list *); -#define LIST_FOR_EACH(ITER, MEMBER, LIST) \ - for (INIT_CONTAINER(ITER, (LIST)->next, MEMBER); \ - &(ITER)->MEMBER != (LIST); \ - ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.next, MEMBER)) -#define LIST_FOR_EACH_CONTINUE(ITER, MEMBER, LIST) \ - for (ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.next, MEMBER); \ - &(ITER)->MEMBER != (LIST); \ - ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.next, MEMBER)) -#define LIST_FOR_EACH_REVERSE(ITER, MEMBER, LIST) \ - for (INIT_CONTAINER(ITER, (LIST)->prev, MEMBER); \ - &(ITER)->MEMBER != (LIST); \ - ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER)) -#define LIST_FOR_EACH_REVERSE_SAFE(ITER, PREV, MEMBER, LIST) \ - for (INIT_CONTAINER(ITER, (LIST)->prev, MEMBER); \ - (&(ITER)->MEMBER != (LIST) \ - ? INIT_CONTAINER(PREV, (ITER)->MEMBER.prev, MEMBER), 1 \ - : 0); \ - (ITER) = (PREV)) -#define LIST_FOR_EACH_REVERSE_CONTINUE(ITER, MEMBER, LIST) \ - for (ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER); \ - &(ITER)->MEMBER != (LIST); \ - ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER)) -#define LIST_FOR_EACH_SAFE(ITER, NEXT, MEMBER, LIST) \ - for (INIT_CONTAINER(ITER, (LIST)->next, MEMBER); \ - (&(ITER)->MEMBER != (LIST) \ - ? INIT_CONTAINER(NEXT, (ITER)->MEMBER.next, MEMBER), 1 \ - : 0); \ - (ITER) = (NEXT)) -#define LIST_FOR_EACH_POP(ITER, MEMBER, LIST) \ - while (!ovs_list_is_empty(LIST) \ +#define LIST_FOR_EACH(VAR, MEMBER, LIST) \ + for (INIT_MULTIVAR(VAR, MEMBER, (LIST)->next); \ + CONDITION_MULTIVAR(ITER_VAR(VAR) != (LIST), VAR, MEMBER); \ + UPDATE_MULTIVAR((ITER_VAR(VAR) = ITER_VAR(VAR)->next), VAR)) + +#define LIST_FOR_EACH_CONTINUE(VAR, MEMBER, LIST) \ + for (INIT_MULTIVAR(VAR, MEMBER, VAR->MEMBER.next); \ + CONDITION_MULTIVAR(ITER_VAR(VAR) != (LIST), VAR, MEMBER); \ + UPDATE_MULTIVAR((ITER_VAR(VAR) = ITER_VAR(VAR)->next), VAR)) + +#define LIST_FOR_EACH_REVERSE(VAR, MEMBER, LIST) \ + for (INIT_MULTIVAR(VAR, MEMBER, (LIST)->prev); \ + CONDITION_MULTIVAR(ITER_VAR(VAR) != (LIST), VAR, MEMBER); \ + UPDATE_MULTIVAR((ITER_VAR(VAR) = ITER_VAR(VAR)->prev), VAR)) + + +#define LIST_FOR_EACH_REVERSE_CONTINUE(VAR, MEMBER, LIST) \ + for (INIT_MULTIVAR(VAR, MEMBER, VAR->MEMBER.prev); \ + CONDITION_MULTIVAR(ITER_VAR(VAR) != (LIST), VAR, MEMBER); \ + UPDATE_MULTIVAR((ITER_VAR(VAR) = ITER_VAR(VAR)->prev), VAR)) + +#define LIST_FOR_EACH_REVERSE_SAFE(VAR, PREV, MEMBER, LIST) \ + for (INIT_MULTIVAR_SAFE_EXP(VAR, MEMBER, (LIST)->prev, (void) PREV); \ + CONDITION_MULTIVAR_SAFE(ITER_VAR(VAR) != (LIST), \ + ITER_NEXT_VAR(VAR) = ITER_VAR(VAR)->prev, \ + VAR, MEMBER); \ + UPDATE_MULTIVAR_SAFE(VAR)) + +#define LIST_FOR_EACH_SAFE(VAR, NEXT, MEMBER, LIST) \ + for (INIT_MULTIVAR_SAFE_EXP(VAR, MEMBER, (LIST)->next, (void) NEXT); \ + CONDITION_MULTIVAR_SAFE(ITER_VAR(VAR) != (LIST), \ + ITER_NEXT_VAR(VAR) = ITER_VAR(VAR)->next, \ + VAR, MEMBER); \ + UPDATE_MULTIVAR_SAFE(VAR)) + +#define LIST_FOR_EACH_POP(ITER, MEMBER, LIST) \ + while (!ovs_list_is_empty(LIST) \ && (INIT_CONTAINER(ITER, ovs_list_pop_front(LIST), MEMBER), 1)) /* Inline implementations. */ diff --git a/ofproto/bond.c b/ofproto/bond.c index cdfdf0b9d..6e95dfdff 100644 --- a/ofproto/bond.c +++ b/ofproto/bond.c @@ -1258,7 +1258,7 @@ insert_bal(struct ovs_list *bals, struct bond_member *member) break; } } - ovs_list_insert(&pos->bal_node, &member->bal_node); + ovs_list_insert(pos? &pos->bal_node: bals, &member->bal_node); } /* Removes 'member' from its current list and then inserts it into 'bals' so diff --git a/tests/test-list.c b/tests/test-list.c index 6f1fb059b..30a0be17b 100644 --- a/tests/test-list.c +++ b/tests/test-list.c @@ -61,7 +61,7 @@ check_list(struct ovs_list *list, const int values[], size_t n) assert(e->value == values[i]); i++; } - assert(&e->node == list); + assert(e == NULL); assert(i == n); i = 0; @@ -70,7 +70,7 @@ check_list(struct ovs_list *list, const int values[], size_t n) assert(e->value == values[n - i - 1]); i++; } - assert(&e->node == list); + assert(e == NULL); assert(i == n); assert(ovs_list_is_empty(list) == !n); @@ -148,7 +148,7 @@ test_list_for_each_safe(void) i++; } assert(i == n); - assert(&e->node == &list); + assert(e == NULL); for (i = 0; i < n; i++) { if (pattern & (1ul << i)) { From patchwork Mon Jan 24 10:34:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cK++qVuY; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5wg6RCyz9t0k for ; Mon, 24 Jan 2022 21:35:31 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9073983ED7; Mon, 24 Jan 2022 10:35:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z_T6qfUTKXCk; Mon, 24 Jan 2022 10:35:28 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 0C70983F0B; Mon, 24 Jan 2022 10:35:26 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0C164C007E; Mon, 24 Jan 2022 10:35:26 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 20782C0072 for ; Mon, 24 Jan 2022 10:35:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 73B6483F05 for ; Mon, 24 Jan 2022 10:35:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SKQBX75dZL9P for ; Mon, 24 Jan 2022 10:35:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6188183E59 for ; Mon, 24 Jan 2022 10:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oH02652Sq/5DzO9bIplrxpjQHVqwsQ2v8y/yR6VSO54=; b=cK++qVuYD89XJt+XuouFDS2xxiQzHJkI4BsZNTbGngVAof229IZoclAwRbrv1ckdQnm0wZ DTrgOBrNycyJ2elhnHEwmPWiTWQwRJcDsu9K3i8UBtX+OCvxF/Y6xrhy2pSDACHY1RJcw0 upL3jJiKawoc7441bj0m3LJtnMGabQk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-396-hkqlbL8OPfqPuQwL3tFreQ-1; Mon, 24 Jan 2022 05:35:19 -0500 X-MC-Unique: hkqlbL8OPfqPuQwL3tFreQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D6CC1083F62; Mon, 24 Jan 2022 10:35:18 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AA327A2ED; Mon, 24 Jan 2022 10:35:16 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:36 +0100 Message-Id: <20220124103445.2459400-5-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 04/13] list: ensure iterator is NULL after pop loop X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" After the loop ends, the iterator is not guaranteed to point to a valid object and should not be used. Make it NULL to avoid undefined behavior. Signed-off-by: Adrian Moreno --- include/openvswitch/list.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/openvswitch/list.h b/include/openvswitch/list.h index 263789b60..a63a51759 100644 --- a/include/openvswitch/list.h +++ b/include/openvswitch/list.h @@ -108,8 +108,9 @@ static inline bool ovs_list_is_short(const struct ovs_list *); UPDATE_MULTIVAR_SAFE(VAR)) #define LIST_FOR_EACH_POP(ITER, MEMBER, LIST) \ - while (!ovs_list_is_empty(LIST) \ - && (INIT_CONTAINER(ITER, ovs_list_pop_front(LIST), MEMBER), 1)) + while (!ovs_list_is_empty(LIST) ? \ + (INIT_CONTAINER(ITER, ovs_list_pop_front(LIST), MEMBER), 1) : \ + (ITER = NULL, 0)) /* Inline implementations. */ From patchwork Mon Jan 24 10:34:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SEN6Ro6O; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5wv31Sbz9t0k for ; Mon, 24 Jan 2022 21:35:43 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 632F241497; Mon, 24 Jan 2022 10:35:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xyxpy359-hwC; Mon, 24 Jan 2022 10:35:36 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 67903409BA; Mon, 24 Jan 2022 10:35:33 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0F655C0072; Mon, 24 Jan 2022 10:35:33 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 135CCC0039 for ; Mon, 24 Jan 2022 10:35:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 47EDB83F6F for ; Mon, 24 Jan 2022 10:35:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j7dtS75-C0DR for ; Mon, 24 Jan 2022 10:35:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 573F183ED7 for ; Mon, 24 Jan 2022 10:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pbkCVgXvSLKilqhuhB9BjKnrghIdT5YuE12Rqhy+lco=; b=SEN6Ro6OCFOoFJhIMY7Vb2EnwY9d7bzivBbP6WpNpxEBkdfiwXC59C41iCDIfiHPcQs7ja v+ULEmehEV8w0RIjnPUun9ocguaWeonfHbrzFMXn/Ve1SSnlz8ty+uydvKu6Bhs8VxpcSl AT3tcBCdAryxuu3dcrQeG20BystWxWU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-147-7pvAC0CKPii5JEBMv0t4Mw-1; Mon, 24 Jan 2022 05:35:22 -0500 X-MC-Unique: 7pvAC0CKPii5JEBMv0t4Mw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1C83814404; Mon, 24 Jan 2022 10:35:20 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D9BB7A235; Mon, 24 Jan 2022 10:35:18 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:37 +0100 Message-Id: <20220124103445.2459400-6-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 05/13] list: remove the next variable in safe loops X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Apart from being safer from the point of view of potential undefined behavior, the multi-variable version of the safe iterators have the benefit of not requiring the declaration of an external variable to hold the next position. This patch removes the extra variable from the LIST_FOR_EACH_SAFE callers. Signed-off-by: Adrian Moreno --- include/openvswitch/list.h | 8 ++++---- lib/conntrack.c | 4 ++-- lib/fat-rwlock.c | 4 ++-- lib/ipf.c | 22 +++++++++++----------- lib/lldp/lldpd-structs.c | 7 +++---- lib/lldp/lldpd.c | 8 ++++---- lib/mcast-snooping.c | 12 ++++++------ lib/netdev-afxdp.c | 4 ++-- lib/netdev-dpdk.c | 4 ++-- lib/ofp-msgs.c | 4 ++-- lib/ovs-lldp.c | 12 ++++++------ lib/ovs-numa.h | 4 ++-- lib/ovsdb-idl.c | 30 +++++++++++++++--------------- lib/seq.c | 4 ++-- lib/tnl-ports.c | 16 ++++++++-------- lib/unixctl.c | 8 ++++---- lib/vconn.c | 4 ++-- ofproto/connmgr.c | 8 ++++---- ofproto/ofproto-dpif-ipfix.c | 4 ++-- ofproto/ofproto-dpif-trace.c | 4 ++-- ofproto/ofproto-dpif-xlate.c | 4 ++-- ofproto/ofproto-dpif.c | 24 +++++++++++------------- ovsdb/jsonrpc-server.c | 16 ++++++++-------- ovsdb/monitor.c | 24 ++++++++++++------------ ovsdb/ovsdb.c | 4 ++-- ovsdb/raft.c | 15 +++++++-------- ovsdb/transaction-forward.c | 6 +++--- ovsdb/transaction.c | 28 ++++++++++++++-------------- ovsdb/trigger.c | 4 ++-- tests/test-list.c | 4 ++-- utilities/ovs-ofctl.c | 4 ++-- utilities/ovs-vsctl.c | 8 ++++---- vswitchd/bridge.c | 16 ++++++++-------- vtep/vtep-ctl.c | 12 ++++++------ 34 files changed, 168 insertions(+), 172 deletions(-) diff --git a/include/openvswitch/list.h b/include/openvswitch/list.h index a63a51759..d604c41c1 100644 --- a/include/openvswitch/list.h +++ b/include/openvswitch/list.h @@ -93,15 +93,15 @@ static inline bool ovs_list_is_short(const struct ovs_list *); CONDITION_MULTIVAR(ITER_VAR(VAR) != (LIST), VAR, MEMBER); \ UPDATE_MULTIVAR((ITER_VAR(VAR) = ITER_VAR(VAR)->prev), VAR)) -#define LIST_FOR_EACH_REVERSE_SAFE(VAR, PREV, MEMBER, LIST) \ - for (INIT_MULTIVAR_SAFE_EXP(VAR, MEMBER, (LIST)->prev, (void) PREV); \ +#define LIST_FOR_EACH_REVERSE_SAFE(VAR, MEMBER, LIST) \ + for (INIT_MULTIVAR_SAFE(VAR, MEMBER, (LIST)->prev); \ CONDITION_MULTIVAR_SAFE(ITER_VAR(VAR) != (LIST), \ ITER_NEXT_VAR(VAR) = ITER_VAR(VAR)->prev, \ VAR, MEMBER); \ UPDATE_MULTIVAR_SAFE(VAR)) -#define LIST_FOR_EACH_SAFE(VAR, NEXT, MEMBER, LIST) \ - for (INIT_MULTIVAR_SAFE_EXP(VAR, MEMBER, (LIST)->next, (void) NEXT); \ +#define LIST_FOR_EACH_SAFE(VAR, MEMBER, LIST) \ + for (INIT_MULTIVAR_SAFE(VAR, MEMBER, (LIST)->next); \ CONDITION_MULTIVAR_SAFE(ITER_VAR(VAR) != (LIST), \ ITER_NEXT_VAR(VAR) = ITER_VAR(VAR)->next, \ VAR, MEMBER); \ diff --git a/lib/conntrack.c b/lib/conntrack.c index 33a1a9295..9c96b69e4 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -1526,14 +1526,14 @@ set_label(struct dp_packet *pkt, struct conn *conn, static long long ct_sweep(struct conntrack *ct, long long now, size_t limit) { - struct conn *conn, *next; + struct conn *conn; long long min_expiration = LLONG_MAX; size_t count = 0; ovs_mutex_lock(&ct->ct_lock); for (unsigned i = 0; i < N_CT_TM; i++) { - LIST_FOR_EACH_SAFE (conn, next, exp_node, &ct->exp_lists[i]) { + LIST_FOR_EACH_SAFE (conn, exp_node, &ct->exp_lists[i]) { ovs_mutex_lock(&conn->lock); if (now < conn->expiration || count >= limit) { min_expiration = MIN(min_expiration, conn->expiration); diff --git a/lib/fat-rwlock.c b/lib/fat-rwlock.c index d913b2088..771ccc973 100644 --- a/lib/fat-rwlock.c +++ b/lib/fat-rwlock.c @@ -97,14 +97,14 @@ fat_rwlock_init(struct fat_rwlock *rwlock) void fat_rwlock_destroy(struct fat_rwlock *rwlock) { - struct fat_rwlock_slot *slot, *next; + struct fat_rwlock_slot *slot; /* Order is important here. By destroying the thread-specific data first, * before we destroy the slots, we ensure that the thread-specific * data destructor can't race with our loop below. */ ovsthread_key_delete(rwlock->key); - LIST_FOR_EACH_SAFE (slot, next, list_node, &rwlock->threads) { + LIST_FOR_EACH_SAFE (slot, list_node, &rwlock->threads) { free_slot(slot); } ovs_mutex_destroy(&rwlock->mutex); diff --git a/lib/ipf.c b/lib/ipf.c index 507db2aea..d45266374 100644 --- a/lib/ipf.c +++ b/lib/ipf.c @@ -1058,9 +1058,9 @@ ipf_send_completed_frags(struct ipf *ipf, struct dp_packet_batch *pb, } ovs_mutex_lock(&ipf->ipf_lock); - struct ipf_list *ipf_list, *next; + struct ipf_list *ipf_list; - LIST_FOR_EACH_SAFE (ipf_list, next, list_node, &ipf->frag_complete_list) { + LIST_FOR_EACH_SAFE (ipf_list, list_node, &ipf->frag_complete_list) { if (ipf_send_frags_in_list(ipf, ipf_list, pb, IPF_FRAG_COMPLETED_LIST, v6, now)) { ipf_completed_list_clean(&ipf->frag_lists, ipf_list); @@ -1090,10 +1090,10 @@ ipf_send_expired_frags(struct ipf *ipf, struct dp_packet_batch *pb, } ovs_mutex_lock(&ipf->ipf_lock); - struct ipf_list *ipf_list, *next; + struct ipf_list *ipf_list; size_t lists_removed = 0; - LIST_FOR_EACH_SAFE (ipf_list, next, list_node, &ipf->frag_exp_list) { + LIST_FOR_EACH_SAFE (ipf_list, list_node, &ipf->frag_exp_list) { if (now <= ipf_list->expiration || lists_removed >= IPF_FRAG_LIST_MAX_EXPIRED) { break; @@ -1121,9 +1121,9 @@ ipf_execute_reass_pkts(struct ipf *ipf, struct dp_packet_batch *pb) } ovs_mutex_lock(&ipf->ipf_lock); - struct reassembled_pkt *rp, *next; + struct reassembled_pkt *rp; - LIST_FOR_EACH_SAFE (rp, next, rp_list_node, &ipf->reassembled_pkt_list) { + LIST_FOR_EACH_SAFE (rp, rp_list_node, &ipf->reassembled_pkt_list) { if (!rp->list->reass_execute_ctx && ipf_dp_packet_batch_add(pb, rp->pkt, false)) { rp->list->reass_execute_ctx = rp->pkt; @@ -1144,9 +1144,9 @@ ipf_post_execute_reass_pkts(struct ipf *ipf, } ovs_mutex_lock(&ipf->ipf_lock); - struct reassembled_pkt *rp, *next; + struct reassembled_pkt *rp; - LIST_FOR_EACH_SAFE (rp, next, rp_list_node, &ipf->reassembled_pkt_list) { + LIST_FOR_EACH_SAFE (rp, rp_list_node, &ipf->reassembled_pkt_list) { const size_t pb_cnt = dp_packet_batch_size(pb); int pb_idx; struct dp_packet *pkt; @@ -1271,15 +1271,15 @@ ipf_clean_thread_main(void *f) ovs_mutex_lock(&ipf->ipf_lock); - struct ipf_list *ipf_list, *next; - LIST_FOR_EACH_SAFE (ipf_list, next, list_node, + struct ipf_list *ipf_list; + LIST_FOR_EACH_SAFE (ipf_list, list_node, &ipf->frag_exp_list) { if (ipf_purge_list_check(ipf, ipf_list, now)) { ipf_expiry_list_clean(&ipf->frag_lists, ipf_list); } } - LIST_FOR_EACH_SAFE (ipf_list, next, list_node, + LIST_FOR_EACH_SAFE (ipf_list, list_node, &ipf->frag_complete_list) { if (ipf_purge_list_check(ipf, ipf_list, now)) { ipf_completed_list_clean(&ipf->frag_lists, ipf_list); diff --git a/lib/lldp/lldpd-structs.c b/lib/lldp/lldpd-structs.c index 499b44174..a8c7fad09 100644 --- a/lib/lldp/lldpd-structs.c +++ b/lib/lldp/lldpd-structs.c @@ -64,11 +64,11 @@ lldpd_remote_cleanup(struct lldpd_hardware *hw, struct lldpd_port *), bool all) { - struct lldpd_port *port, *port_next; + struct lldpd_port *port; time_t now = time_now(); VLOG_DBG("cleanup remote port on %s", hw->h_ifname); - LIST_FOR_EACH_SAFE (port, port_next, p_entries, &hw->h_rports) { + LIST_FOR_EACH_SAFE (port, p_entries, &hw->h_rports) { bool del = all; if (!all && expire && (now >= port->p_lastupdate + port->p_chassis->c_ttl)) { @@ -99,11 +99,10 @@ static void lldpd_aa_maps_cleanup(struct lldpd_port *port) { struct lldpd_aa_isid_vlan_maps_tlv *isid_vlan_map = NULL; - struct lldpd_aa_isid_vlan_maps_tlv *isid_vlan_map_next = NULL; if (!ovs_list_is_empty(&port->p_isid_vlan_maps)) { - LIST_FOR_EACH_SAFE (isid_vlan_map, isid_vlan_map_next, m_entries, + LIST_FOR_EACH_SAFE (isid_vlan_map, m_entries, &port->p_isid_vlan_maps) { ovs_list_remove(&isid_vlan_map->m_entries); diff --git a/lib/lldp/lldpd.c b/lib/lldp/lldpd.c index a024dc5e5..403f1f525 100644 --- a/lib/lldp/lldpd.c +++ b/lib/lldp/lldpd.c @@ -134,12 +134,12 @@ lldpd_hardware_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware) void lldpd_cleanup(struct lldpd *cfg) { - struct lldpd_hardware *hw, *hw_next; - struct lldpd_chassis *chassis, *chassis_next; + struct lldpd_hardware *hw; + struct lldpd_chassis *chassis; VLOG_DBG("cleanup all ports"); - LIST_FOR_EACH_SAFE (hw, hw_next, h_entries, &cfg->g_hardware) { + LIST_FOR_EACH_SAFE (hw, h_entries, &cfg->g_hardware) { if (!hw->h_flags) { ovs_list_remove(&hw->h_entries); lldpd_remote_cleanup(hw, NULL, true); @@ -151,7 +151,7 @@ lldpd_cleanup(struct lldpd *cfg) VLOG_DBG("cleanup all chassis"); - LIST_FOR_EACH_SAFE (chassis, chassis_next, list, &cfg->g_chassis) { + LIST_FOR_EACH_SAFE (chassis, list, &cfg->g_chassis) { if (chassis->c_refcount == 0) { ovs_list_remove(&chassis->list); lldpd_chassis_cleanup(chassis, 1); diff --git a/lib/mcast-snooping.c b/lib/mcast-snooping.c index 6730301b6..029ca2855 100644 --- a/lib/mcast-snooping.c +++ b/lib/mcast-snooping.c @@ -356,11 +356,11 @@ mcast_snooping_prune_expired(struct mcast_snooping *ms, OVS_REQ_WRLOCK(ms->rwlock) { int expired; - struct mcast_group_bundle *b, *next_b; + struct mcast_group_bundle *b; time_t timenow = time_now(); expired = 0; - LIST_FOR_EACH_SAFE (b, next_b, bundle_node, &grp->bundle_lru) { + LIST_FOR_EACH_SAFE (b, bundle_node, &grp->bundle_lru) { /* This list is sorted on expiration time. */ if (b->expires > timenow) { break; @@ -946,15 +946,15 @@ mcast_snooping_wait(struct mcast_snooping *ms) void mcast_snooping_flush_bundle(struct mcast_snooping *ms, void *port) { - struct mcast_group *g, *next_g; - struct mcast_mrouter_bundle *m, *next_m; + struct mcast_group *g; + struct mcast_mrouter_bundle *m; if (!mcast_snooping_enabled(ms)) { return; } ovs_rwlock_wrlock(&ms->rwlock); - LIST_FOR_EACH_SAFE (g, next_g, group_node, &ms->group_lru) { + LIST_FOR_EACH_SAFE (g, group_node, &ms->group_lru) { if (mcast_group_delete_bundle(ms, g, port)) { ms->need_revalidate = true; @@ -964,7 +964,7 @@ mcast_snooping_flush_bundle(struct mcast_snooping *ms, void *port) } } - LIST_FOR_EACH_SAFE (m, next_m, mrouter_node, &ms->mrouter_lru) { + LIST_FOR_EACH_SAFE (m, mrouter_node, &ms->mrouter_lru) { if (m->port == port) { mcast_snooping_flush_mrouter(m); ms->need_revalidate = true; diff --git a/lib/netdev-afxdp.c b/lib/netdev-afxdp.c index 482400d8d..ca3f2431e 100644 --- a/lib/netdev-afxdp.c +++ b/lib/netdev-afxdp.c @@ -235,11 +235,11 @@ netdev_afxdp_cleanup_unused_pool(struct unused_pool *pool) static void netdev_afxdp_sweep_unused_pools(void *aux OVS_UNUSED) { - struct unused_pool *pool, *next; + struct unused_pool *pool; unsigned int count; ovs_mutex_lock(&unused_pools_mutex); - LIST_FOR_EACH_SAFE (pool, next, list_node, &unused_pools) { + LIST_FOR_EACH_SAFE (pool, list_node, &unused_pools) { count = umem_pool_count(&pool->umem_info->mpool); ovs_assert(count + pool->lost_in_rings <= NUM_FRAMES); diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 6782d3e8f..ef9a05d67 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -621,9 +621,9 @@ dpdk_mp_full(const struct rte_mempool *mp) OVS_REQUIRES(dpdk_mp_mutex) static void dpdk_mp_sweep(void) OVS_REQUIRES(dpdk_mp_mutex) { - struct dpdk_mp *dmp, *next; + struct dpdk_mp *dmp; - LIST_FOR_EACH_SAFE (dmp, next, list_node, &dpdk_mp_list) { + LIST_FOR_EACH_SAFE (dmp, list_node, &dpdk_mp_list) { if (!dmp->refcount && dpdk_mp_full(dmp->mp)) { VLOG_DBG("Freeing mempool \"%s\"", dmp->mp->name); ovs_list_remove(&dmp->list_node); diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c index fec54f75f..8f969ee59 100644 --- a/lib/ofp-msgs.c +++ b/lib/ofp-msgs.c @@ -1290,8 +1290,8 @@ ofpmp_assembler_execute(struct hmap *assembler, struct ofpbuf *msg, * on either side by parts with 0-byte bodies. We remove the 0-byte * ones here to simplify processing later. */ - struct ofpbuf *b, *next; - LIST_FOR_EACH_SAFE (b, next, list_node, out) { + struct ofpbuf *b; + LIST_FOR_EACH_SAFE (b, list_node, out) { if (b->size <= min_len && !ovs_list_is_short(out)) { ovs_list_remove(&b->list_node); ofpbuf_delete(b); diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c index 162311fa4..a9d205ec8 100644 --- a/lib/ovs-lldp.c +++ b/lib/ovs-lldp.c @@ -559,9 +559,9 @@ aa_mapping_unregister_mapping(struct lldp *lldp, struct lldpd_hardware *hw, struct aa_mapping_internal *m) { - struct lldpd_aa_isid_vlan_maps_tlv *lm, *lm_next; + struct lldpd_aa_isid_vlan_maps_tlv *lm; - LIST_FOR_EACH_SAFE (lm, lm_next, m_entries, + LIST_FOR_EACH_SAFE (lm, m_entries, &hw->h_lport.p_isid_vlan_maps) { uint32_t isid = lm->isid_vlan_data.isid; @@ -953,8 +953,8 @@ lldp_ref(const struct lldp *lldp_) void lldp_destroy_dummy(struct lldp *lldp) { - struct lldpd_hardware *hw, *hw_next; - struct lldpd_chassis *chassis, *chassis_next; + struct lldpd_hardware *hw; + struct lldpd_chassis *chassis; struct lldpd *cfg; if (!lldp) { @@ -963,13 +963,13 @@ lldp_destroy_dummy(struct lldp *lldp) cfg = lldp->lldpd; - LIST_FOR_EACH_SAFE (hw, hw_next, h_entries, &cfg->g_hardware) { + LIST_FOR_EACH_SAFE (hw, h_entries, &cfg->g_hardware) { ovs_list_remove(&hw->h_entries); free(hw->h_lport.p_lastframe); free(hw); } - LIST_FOR_EACH_SAFE (chassis, chassis_next, list, &cfg->g_chassis) { + LIST_FOR_EACH_SAFE (chassis, list, &cfg->g_chassis) { ovs_list_remove(&chassis->list); free(chassis); } diff --git a/lib/ovs-numa.h b/lib/ovs-numa.h index ecc251a7f..3adb7c344 100644 --- a/lib/ovs-numa.h +++ b/lib/ovs-numa.h @@ -68,9 +68,9 @@ void ovs_numa_dump_destroy(struct ovs_numa_dump *); int ovs_numa_thread_setaffinity_core(unsigned core_id); #define FOR_EACH_CORE_ON_DUMP(ITER, DUMP) \ - HMAP_FOR_EACH((ITER), hmap_node, &(DUMP)->cores) + HMAP_FOR_EACH(ITER, hmap_node, &(DUMP)->cores) #define FOR_EACH_NUMA_ON_DUMP(ITER, DUMP) \ - HMAP_FOR_EACH((ITER), hmap_node, &(DUMP)->numas) + HMAP_FOR_EACH(ITER, hmap_node, &(DUMP)->numas) #endif /* ovs-numa.h */ diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index b7ba25eca..b0e03ef1f 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -396,18 +396,18 @@ ovsdb_idl_clear(struct ovsdb_idl *db) } HMAP_FOR_EACH_SAFE (row, next_row, hmap_node, &table->rows) { - struct ovsdb_idl_arc *arc, *next_arc; + struct ovsdb_idl_arc *arc; if (!ovsdb_idl_row_is_orphan(row)) { ovsdb_idl_remove_from_indexes(row); ovsdb_idl_row_unparse(row); } - LIST_FOR_EACH_SAFE (arc, next_arc, src_node, &row->src_arcs) { + LIST_FOR_EACH_SAFE (arc, src_node, &row->src_arcs) { ovs_list_remove(&arc->src_node); ovs_list_remove(&arc->dst_node); free(arc); } - LIST_FOR_EACH_SAFE (arc, next_arc, dst_node, &row->dst_arcs) { + LIST_FOR_EACH_SAFE (arc, dst_node, &row->dst_arcs) { ovs_list_remove(&arc->src_node); ovs_list_remove(&arc->dst_node); free(arc); @@ -1345,9 +1345,9 @@ ovsdb_idl_track_clear__(struct ovsdb_idl *idl, bool flush_all) struct ovsdb_idl_table *table = &idl->tables[i]; if (!ovs_list_is_empty(&table->track_list)) { - struct ovsdb_idl_row *row, *next; + struct ovsdb_idl_row *row; - LIST_FOR_EACH_SAFE(row, next, track_node, &table->track_list) { + LIST_FOR_EACH_SAFE(row, track_node, &table->track_list) { if (row->updated) { free(row->updated); row->updated = NULL; @@ -1480,9 +1480,9 @@ ovsdb_idl_parse_update(struct ovsdb_idl *idl, static void ovsdb_idl_reparse_deleted(struct ovsdb_idl *db) { - struct ovsdb_idl_row *row, *next; + struct ovsdb_idl_row *row; - LIST_FOR_EACH_SAFE (row, next, track_node, &db->deleted_untracked_rows) { + LIST_FOR_EACH_SAFE (row, track_node, &db->deleted_untracked_rows) { ovsdb_idl_row_untrack_change(row); add_tracked_change_for_references(row); ovsdb_idl_row_reparse_backrefs(row); @@ -1906,8 +1906,8 @@ ovsdb_idl_index_create2(struct ovsdb_idl *idl, static void ovsdb_idl_destroy_indexes(struct ovsdb_idl_table *table) { - struct ovsdb_idl_index *index, *next; - LIST_FOR_EACH_SAFE (index, next, node, &table->indexes) { + struct ovsdb_idl_index *index; + LIST_FOR_EACH_SAFE (index, node, &table->indexes) { skiplist_destroy(index->skiplist, NULL); free(index->columns); free(index); @@ -2145,12 +2145,12 @@ ovsdb_idl_row_clear_new(struct ovsdb_idl_row *row) static void ovsdb_idl_row_clear_arcs(struct ovsdb_idl_row *row, bool destroy_dsts) { - struct ovsdb_idl_arc *arc, *next; + struct ovsdb_idl_arc *arc; /* Delete all forward arcs. If 'destroy_dsts', destroy any orphaned rows * that this causes to be unreferenced. */ - LIST_FOR_EACH_SAFE (arc, next, src_node, &row->src_arcs) { + LIST_FOR_EACH_SAFE (arc, src_node, &row->src_arcs) { ovs_list_remove(&arc->dst_node); if (destroy_dsts && ovsdb_idl_row_is_orphan(arc->dst) @@ -2166,7 +2166,7 @@ ovsdb_idl_row_clear_arcs(struct ovsdb_idl_row *row, bool destroy_dsts) static void ovsdb_idl_row_reparse_backrefs(struct ovsdb_idl_row *row) { - struct ovsdb_idl_arc *arc, *next; + struct ovsdb_idl_arc *arc; /* This is trickier than it looks. ovsdb_idl_row_clear_arcs() will destroy * 'arc', so we need to use the "safe" variant of list traversal. However, @@ -2178,7 +2178,7 @@ ovsdb_idl_row_reparse_backrefs(struct ovsdb_idl_row *row) * (If duplicate arcs were possible then we would need to make sure that * 'next' didn't also point into 'arc''s destination, but we forbid * duplicate arcs.) */ - LIST_FOR_EACH_SAFE (arc, next, dst_node, &row->dst_arcs) { + LIST_FOR_EACH_SAFE (arc, dst_node, &row->dst_arcs) { struct ovsdb_idl_row *ref = arc->src; ovsdb_idl_row_unparse(ref); @@ -2329,9 +2329,9 @@ ovsdb_idl_row_destroy_postprocess(struct ovsdb_idl *idl) struct ovsdb_idl_table *table = &idl->tables[i]; if (!ovs_list_is_empty(&table->track_list)) { - struct ovsdb_idl_row *row, *next; + struct ovsdb_idl_row *row; - LIST_FOR_EACH_SAFE(row, next, track_node, &table->track_list) { + LIST_FOR_EACH_SAFE(row, track_node, &table->track_list) { if (!ovsdb_idl_track_is_set(row->table)) { ovs_list_remove(&row->track_node); ovsdb_idl_row_unparse(row); diff --git a/lib/seq.c b/lib/seq.c index 6581cb06b..2434ccb5d 100644 --- a/lib/seq.c +++ b/lib/seq.c @@ -297,9 +297,9 @@ static void seq_thread_woke(struct seq_thread *thread) OVS_REQUIRES(seq_mutex) { - struct seq_waiter *waiter, *next_waiter; + struct seq_waiter *waiter; - LIST_FOR_EACH_SAFE (waiter, next_waiter, list_node, &thread->waiters) { + LIST_FOR_EACH_SAFE (waiter, list_node, &thread->waiters) { ovs_assert(waiter->thread == thread); seq_waiter_destroy(waiter); } diff --git a/lib/tnl-ports.c b/lib/tnl-ports.c index 58269d3b1..789f996d1 100644 --- a/lib/tnl-ports.c +++ b/lib/tnl-ports.c @@ -259,14 +259,14 @@ ipdev_map_delete(struct ip_device *ip_dev, ovs_be16 tp_port, uint8_t nw_proto) void tnl_port_map_delete(odp_port_t port, const char type[]) { - struct tnl_port *p, *next; + struct tnl_port *p; struct ip_device *ip_dev; uint8_t nw_proto; nw_proto = tnl_type_to_nw_proto(type); ovs_mutex_lock(&mutex); - LIST_FOR_EACH_SAFE(p, next, node, &port_list) { + LIST_FOR_EACH_SAFE(p, node, &port_list) { if (p->port == port && p->nw_proto == nw_proto && ovs_refcount_unref_relaxed(&p->ref_cnt) == 1) { ovs_list_remove(&p->node); @@ -444,11 +444,11 @@ delete_ipdev(struct ip_device *ip_dev) void tnl_port_map_insert_ipdev(const char dev_name[]) { - struct ip_device *ip_dev, *next; + struct ip_device *ip_dev; ovs_mutex_lock(&mutex); - LIST_FOR_EACH_SAFE(ip_dev, next, node, &addr_list) { + LIST_FOR_EACH_SAFE(ip_dev, node, &addr_list) { if (!strcmp(netdev_get_name(ip_dev->dev), dev_name)) { if (ip_dev->change_seq == netdev_get_change_seq(ip_dev->dev)) { goto out; @@ -466,10 +466,10 @@ out: void tnl_port_map_delete_ipdev(const char dev_name[]) { - struct ip_device *ip_dev, *next; + struct ip_device *ip_dev; ovs_mutex_lock(&mutex); - LIST_FOR_EACH_SAFE(ip_dev, next, node, &addr_list) { + LIST_FOR_EACH_SAFE(ip_dev, node, &addr_list) { if (!strcmp(netdev_get_name(ip_dev->dev), dev_name)) { delete_ipdev(ip_dev); } @@ -480,10 +480,10 @@ tnl_port_map_delete_ipdev(const char dev_name[]) void tnl_port_map_run(void) { - struct ip_device *ip_dev, *next; + struct ip_device *ip_dev; ovs_mutex_lock(&mutex); - LIST_FOR_EACH_SAFE(ip_dev, next, node, &addr_list) { + LIST_FOR_EACH_SAFE(ip_dev, node, &addr_list) { char dev_name[IFNAMSIZ]; if (ip_dev->change_seq == netdev_get_change_seq(ip_dev->dev)) { diff --git a/lib/unixctl.c b/lib/unixctl.c index 69aed6722..103357ee9 100644 --- a/lib/unixctl.c +++ b/lib/unixctl.c @@ -390,8 +390,8 @@ unixctl_server_run(struct unixctl_server *server) } } - struct unixctl_conn *conn, *next; - LIST_FOR_EACH_SAFE (conn, next, node, &server->conns) { + struct unixctl_conn *conn; + LIST_FOR_EACH_SAFE (conn, node, &server->conns) { int error = run_connection(conn); if (error && error != EAGAIN) { kill_connection(conn); @@ -422,9 +422,9 @@ void unixctl_server_destroy(struct unixctl_server *server) { if (server) { - struct unixctl_conn *conn, *next; + struct unixctl_conn *conn; - LIST_FOR_EACH_SAFE (conn, next, node, &server->conns) { + LIST_FOR_EACH_SAFE (conn, node, &server->conns) { kill_connection(conn); } diff --git a/lib/vconn.c b/lib/vconn.c index 7415e6291..b55676227 100644 --- a/lib/vconn.c +++ b/lib/vconn.c @@ -960,8 +960,8 @@ vconn_transact_multipart(struct vconn *vconn, ovs_list_init(replies); /* Send all the requests. */ - struct ofpbuf *b, *next; - LIST_FOR_EACH_SAFE (b, next, list_node, requests) { + struct ofpbuf *b; + LIST_FOR_EACH_SAFE (b, list_node, requests) { ovs_list_remove(&b->list_node); int error = vconn_send_block(vconn, b); if (error) { diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index fa8f6cd0e..5666d7283 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -351,8 +351,8 @@ connmgr_run(struct connmgr *mgr, } } - struct ofconn *ofconn, *next_ofconn; - LIST_FOR_EACH_SAFE (ofconn, next_ofconn, connmgr_node, &mgr->conns) { + struct ofconn *ofconn; + LIST_FOR_EACH_SAFE (ofconn, connmgr_node, &mgr->conns) { ofconn_run(ofconn, handle_openflow); } ofmonitor_run(mgr); @@ -1953,8 +1953,8 @@ static void ofservice_close_all(struct ofservice *ofservice) OVS_REQUIRES(ofproto_mutex) { - struct ofconn *ofconn, *next; - LIST_FOR_EACH_SAFE (ofconn, next, ofservice_node, &ofservice->conns) { + struct ofconn *ofconn; + LIST_FOR_EACH_SAFE (ofconn, ofservice_node, &ofservice->conns) { ofconn_destroy(ofconn); } } diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c index 796eb6f88..f5ae6c16c 100644 --- a/ofproto/ofproto-dpif-ipfix.c +++ b/ofproto/ofproto-dpif-ipfix.c @@ -2799,7 +2799,7 @@ dpif_ipfix_cache_expire(struct dpif_ipfix_exporter *exporter, bool forced_end, const uint64_t export_time_usec, const uint32_t export_time_sec) { - struct ipfix_flow_cache_entry *entry, *next_entry; + struct ipfix_flow_cache_entry *entry; uint64_t max_flow_start_timestamp_usec; bool template_msg_sent = false; enum ipfix_flow_end_reason flow_end_reason; @@ -2811,7 +2811,7 @@ dpif_ipfix_cache_expire(struct dpif_ipfix_exporter *exporter, max_flow_start_timestamp_usec = export_time_usec - 1000000LL * exporter->cache_active_timeout; - LIST_FOR_EACH_SAFE (entry, next_entry, cache_flow_start_timestamp_list_node, + LIST_FOR_EACH_SAFE (entry, cache_flow_start_timestamp_list_node, &exporter->cache_flow_start_timestamp_list) { if (forced_end) { flow_end_reason = FORCED_END; diff --git a/ofproto/ofproto-dpif-trace.c b/ofproto/ofproto-dpif-trace.c index 78a54c715..109940ad2 100644 --- a/ofproto/ofproto-dpif-trace.c +++ b/ofproto/ofproto-dpif-trace.c @@ -65,8 +65,8 @@ static void oftrace_node_list_destroy(struct ovs_list *nodes) { if (nodes) { - struct oftrace_node *node, *next; - LIST_FOR_EACH_SAFE (node, next, node, nodes) { + struct oftrace_node *node; + LIST_FOR_EACH_SAFE (node, node, nodes) { ovs_list_remove(&node->node); oftrace_node_destroy(node); } diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index cafcd014a..4fdfde91a 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -1282,7 +1282,7 @@ xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name, static void xlate_xbridge_remove(struct xlate_cfg *xcfg, struct xbridge *xbridge) { - struct xbundle *xbundle, *next_xbundle; + struct xbundle *xbundle; struct xport *xport, *next_xport; if (!xbridge) { @@ -1293,7 +1293,7 @@ xlate_xbridge_remove(struct xlate_cfg *xcfg, struct xbridge *xbridge) xlate_xport_remove(xcfg, xport); } - LIST_FOR_EACH_SAFE (xbundle, next_xbundle, list_node, &xbridge->xbundles) { + LIST_FOR_EACH_SAFE (xbundle, list_node, &xbridge->xbundles) { xlate_xbundle_remove(xcfg, xbundle); } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index bc3df8ea1..d9f82924b 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1907,7 +1907,7 @@ run(struct ofproto *ofproto_) new_dump_seq = seq_read(udpif_dump_seq(ofproto->backer->udpif)); if (ofproto->dump_seq != new_dump_seq) { - struct rule *rule, *next_rule; + struct rule *rule; long long now = time_msec(); /* We know stats are relatively fresh, so now is a good time to do some @@ -1917,7 +1917,7 @@ run(struct ofproto *ofproto_) /* Expire OpenFlow flows whose idle_timeout or hard_timeout * has passed. */ ovs_mutex_lock(&ofproto_mutex); - LIST_FOR_EACH_SAFE (rule, next_rule, expirable, + LIST_FOR_EACH_SAFE (rule, expirable, &ofproto->up.expirable) { rule_expire(rule_dpif_cast(rule), now); } @@ -3068,11 +3068,11 @@ bundle_flush_macs(struct ofbundle *bundle, bool all_ofprotos) { struct ofproto_dpif *ofproto = bundle->ofproto; struct mac_learning *ml = ofproto->ml; - struct mac_entry *mac, *next_mac; + struct mac_entry *mac; ofproto->backer->need_revalidate = REV_RECONFIGURE; ovs_rwlock_wrlock(&ml->rwlock); - LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) { + LIST_FOR_EACH_SAFE (mac, lru_node, &ml->lrus) { if (mac_entry_get_port(ml, mac) == bundle) { if (all_ofprotos) { struct ofproto_dpif *o; @@ -3103,13 +3103,13 @@ bundle_move(struct ofbundle *old, struct ofbundle *new) { struct ofproto_dpif *ofproto = old->ofproto; struct mac_learning *ml = ofproto->ml; - struct mac_entry *mac, *next_mac; + struct mac_entry *mac; ovs_assert(new->ofproto == old->ofproto); ofproto->backer->need_revalidate = REV_RECONFIGURE; ovs_rwlock_wrlock(&ml->rwlock); - LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) { + LIST_FOR_EACH_SAFE (mac, lru_node, &ml->lrus) { if (mac_entry_get_port(ml, mac) == old) { mac_entry_set_port(ml, mac, new); } @@ -3206,7 +3206,7 @@ static void bundle_destroy(struct ofbundle *bundle) { struct ofproto_dpif *ofproto; - struct ofport_dpif *port, *next_port; + struct ofport_dpif *port; if (!bundle) { return; @@ -3219,7 +3219,7 @@ bundle_destroy(struct ofbundle *bundle) xlate_bundle_remove(bundle); xlate_txn_commit(); - LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) { + LIST_FOR_EACH_SAFE (port, bundle_node, &bundle->ports) { bundle_del_port(port); } @@ -3309,9 +3309,7 @@ bundle_set(struct ofproto *ofproto_, void *aux, } } if (!ok || ovs_list_size(&bundle->ports) != s->n_members) { - struct ofport_dpif *next_port; - - LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) { + LIST_FOR_EACH_SAFE (port, bundle_node, &bundle->ports) { for (i = 0; i < s->n_members; i++) { if (s->members[i] == port->up.ofp_port) { goto found; @@ -5512,9 +5510,9 @@ ct_zone_timeout_policy_sweep(struct dpif_backer *backer) { if (!ovs_list_is_empty(&backer->ct_tp_kill_list) && time_msec() >= timeout_policy_cleanup_timer) { - struct ct_timeout_policy *ct_tp, *next; + struct ct_timeout_policy *ct_tp; - LIST_FOR_EACH_SAFE (ct_tp, next, list_node, &backer->ct_tp_kill_list) { + LIST_FOR_EACH_SAFE (ct_tp, list_node, &backer->ct_tp_kill_list) { if (!ct_dpif_del_timeout_policy(backer->dpif, ct_tp->tp_id)) { ovs_list_remove(&ct_tp->list_node); ct_timeout_policy_destroy(ct_tp, backer->tp_ids); diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 351c39d8a..d091602d5 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -585,9 +585,9 @@ ovsdb_jsonrpc_session_set_options(struct ovsdb_jsonrpc_session *session, static void ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *remote) { - struct ovsdb_jsonrpc_session *s, *next; + struct ovsdb_jsonrpc_session *s; - LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) { + LIST_FOR_EACH_SAFE (s, node, &remote->sessions) { int error = ovsdb_jsonrpc_session_run(s); if (error) { ovsdb_jsonrpc_session_close(s); @@ -642,9 +642,9 @@ ovsdb_jsonrpc_session_get_memory_usage_all( static void ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *remote) { - struct ovsdb_jsonrpc_session *s, *next; + struct ovsdb_jsonrpc_session *s; - LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) { + LIST_FOR_EACH_SAFE (s, node, &remote->sessions) { ovsdb_jsonrpc_session_close(s); } } @@ -660,9 +660,9 @@ static void ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *remote, bool force, const char *comment) { - struct ovsdb_jsonrpc_session *s, *next; + struct ovsdb_jsonrpc_session *s; - LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) { + LIST_FOR_EACH_SAFE (s, node, &remote->sessions) { if (force || !s->db_change_aware) { jsonrpc_session_force_reconnect(s->js); if (comment && jsonrpc_session_is_connected(s->js)) { @@ -1226,8 +1226,8 @@ ovsdb_jsonrpc_trigger_complete_all(struct ovsdb_jsonrpc_session *s) static void ovsdb_jsonrpc_trigger_complete_done(struct ovsdb_jsonrpc_session *s) { - struct ovsdb_jsonrpc_trigger *trigger, *next; - LIST_FOR_EACH_SAFE (trigger, next, trigger.node, &s->up.completions) { + struct ovsdb_jsonrpc_trigger *trigger; + LIST_FOR_EACH_SAFE (trigger, trigger.node, &s->up.completions) { ovsdb_jsonrpc_trigger_complete(trigger); } } diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index ab814cf20..11777ecf7 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -634,8 +634,8 @@ ovsdb_monitor_change_set_destroy(struct ovsdb_monitor_change_set *mcs) { ovs_list_remove(&mcs->list_node); - struct ovsdb_monitor_change_set_for_table *mcst, *next_mcst; - LIST_FOR_EACH_SAFE (mcst, next_mcst, list_in_change_set, + struct ovsdb_monitor_change_set_for_table *mcst; + LIST_FOR_EACH_SAFE (mcst, list_in_change_set, &mcs->change_set_for_tables) { ovs_list_remove(&mcst->list_in_change_set); ovs_list_remove(&mcst->list_in_mt); @@ -1707,8 +1707,8 @@ ovsdb_monitor_destroy(struct ovsdb_monitor *dbmon) ovsdb_monitor_json_cache_flush(dbmon); hmap_destroy(&dbmon->json_cache); - struct ovsdb_monitor_change_set *cs, *cs_next; - LIST_FOR_EACH_SAFE (cs, cs_next, list_node, &dbmon->change_sets) { + struct ovsdb_monitor_change_set *cs; + LIST_FOR_EACH_SAFE (cs, list_node, &dbmon->change_sets) { ovsdb_monitor_change_set_destroy(cs); } @@ -1756,14 +1756,14 @@ ovsdb_monitors_commit(struct ovsdb *db, const struct ovsdb_txn *txn) void ovsdb_monitors_remove(struct ovsdb *db) { - struct ovsdb_monitor *m, *next_m; + struct ovsdb_monitor *m; - LIST_FOR_EACH_SAFE (m, next_m, list_node, &db->monitors) { - struct jsonrpc_monitor_node *jm, *next_jm; + LIST_FOR_EACH_SAFE (m, list_node, &db->monitors) { + struct jsonrpc_monitor_node *jm; /* Delete all front-end monitors. Removing the last front-end monitor * will also destroy the corresponding ovsdb_monitor. */ - LIST_FOR_EACH_SAFE (jm, next_jm, node, &m->jsonrpc_monitors) { + LIST_FOR_EACH_SAFE (jm, node, &m->jsonrpc_monitors) { ovsdb_jsonrpc_monitor_destroy(jm->jsonrpc_monitor, false); } } @@ -1785,14 +1785,14 @@ ovsdb_monitor_get_memory_usage(struct simap *usage) void ovsdb_monitor_prereplace_db(struct ovsdb *db) { - struct ovsdb_monitor *m, *next_m; + struct ovsdb_monitor *m; - LIST_FOR_EACH_SAFE (m, next_m, list_node, &db->monitors) { - struct jsonrpc_monitor_node *jm, *next_jm; + LIST_FOR_EACH_SAFE (m, list_node, &db->monitors) { + struct jsonrpc_monitor_node *jm; /* Delete all front-end monitors. Removing the last front-end monitor * will also destroy the corresponding ovsdb_monitor. */ - LIST_FOR_EACH_SAFE (jm, next_jm, node, &m->jsonrpc_monitors) { + LIST_FOR_EACH_SAFE (jm, node, &m->jsonrpc_monitors) { ovsdb_jsonrpc_monitor_destroy(jm->jsonrpc_monitor, true); } } diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c index e6d866182..91b4a01af 100644 --- a/ovsdb/ovsdb.c +++ b/ovsdb/ovsdb.c @@ -571,8 +571,8 @@ ovsdb_replace(struct ovsdb *dst, struct ovsdb *src) ovsdb_monitor_prereplace_db(dst); /* Cancel triggers. */ - struct ovsdb_trigger *trigger, *next; - LIST_FOR_EACH_SAFE (trigger, next, node, &dst->triggers) { + struct ovsdb_trigger *trigger; + LIST_FOR_EACH_SAFE (trigger, node, &dst->triggers) { ovsdb_trigger_prereplace_db(trigger); } diff --git a/ovsdb/raft.c b/ovsdb/raft.c index 1a3447a8d..6666df0d7 100644 --- a/ovsdb/raft.c +++ b/ovsdb/raft.c @@ -1376,8 +1376,8 @@ raft_close__(struct raft *raft) raft->remove_server = NULL; } - struct raft_conn *conn, *next; - LIST_FOR_EACH_SAFE (conn, next, list_node, &raft->conns) { + struct raft_conn *conn; + LIST_FOR_EACH_SAFE (conn, list_node, &raft->conns) { raft_conn_close(conn); } } @@ -1713,8 +1713,8 @@ raft_waiters_run(struct raft *raft) } uint64_t cur = ovsdb_log_commit_progress(raft->log); - struct raft_waiter *w, *next; - LIST_FOR_EACH_SAFE (w, next, list_node, &raft->waiters) { + struct raft_waiter *w; + LIST_FOR_EACH_SAFE (w, list_node, &raft->waiters) { if (cur < w->commit_ticket) { break; } @@ -1736,8 +1736,8 @@ raft_waiters_wait(struct raft *raft) static void raft_waiters_destroy(struct raft *raft) { - struct raft_waiter *w, *next; - LIST_FOR_EACH_SAFE (w, next, list_node, &raft->waiters) { + struct raft_waiter *w; + LIST_FOR_EACH_SAFE (w, list_node, &raft->waiters) { raft_waiter_destroy(w); } } @@ -1957,8 +1957,7 @@ raft_run(struct raft *raft) } /* Close unneeded sessions. */ - struct raft_conn *next; - LIST_FOR_EACH_SAFE (conn, next, list_node, &raft->conns) { + LIST_FOR_EACH_SAFE (conn, list_node, &raft->conns) { if (!raft_conn_should_stay_open(raft, conn)) { raft->n_disconnections++; raft_conn_close(conn); diff --git a/ovsdb/transaction-forward.c b/ovsdb/transaction-forward.c index d15f2f1d6..4549e3427 100644 --- a/ovsdb/transaction-forward.c +++ b/ovsdb/transaction-forward.c @@ -126,10 +126,10 @@ ovsdb_txn_forward_steal_reply(struct ovsdb_txn_forward *txn_fwd) void ovsdb_txn_forward_run(struct ovsdb *db, struct ovsdb_cs *cs) { - struct ovsdb_txn_forward *t, *next; + struct ovsdb_txn_forward *t; /* Send all transactions that needs to be forwarded. */ - LIST_FOR_EACH_SAFE (t, next, new_node, &db->txn_forward_new) { + LIST_FOR_EACH_SAFE (t, new_node, &db->txn_forward_new) { if (!ovsdb_cs_may_send_transaction(cs)) { break; } @@ -177,7 +177,7 @@ ovsdb_txn_forward_cancel_all(struct ovsdb *db, bool sent_only) return; } - LIST_FOR_EACH_SAFE (t, next, new_node, &db->txn_forward_new) { + LIST_FOR_EACH_SAFE (t, new_node, &db->txn_forward_new) { ovsdb_txn_forward_cancel(db, t); } } diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index 88e052800..a51c365ab 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -159,15 +159,15 @@ ovsdb_txn_row_abort(struct ovsdb_txn *txn OVS_UNUSED, hmap_replace(&new->table->rows, &new->hmap_node, &old->hmap_node); } - struct ovsdb_weak_ref *weak, *next; - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->deleted_refs) { + struct ovsdb_weak_ref *weak; + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->deleted_refs) { ovs_list_remove(&weak->src_node); ovs_list_init(&weak->src_node); if (hmap_node_is_null(&weak->dst_node)) { ovsdb_weak_ref_destroy(weak); } } - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->added_refs) { + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->added_refs) { ovs_list_remove(&weak->src_node); ovs_list_init(&weak->src_node); if (hmap_node_is_null(&weak->dst_node)) { @@ -508,11 +508,11 @@ static struct ovsdb_error * ovsdb_txn_update_weak_refs(struct ovsdb_txn *txn OVS_UNUSED, struct ovsdb_txn_row *txn_row) { - struct ovsdb_weak_ref *weak, *next, *dst_weak; + struct ovsdb_weak_ref *weak, *dst_weak; struct ovsdb_row *dst_row; /* Find and clean up deleted references from destination rows. */ - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->deleted_refs) { + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->deleted_refs) { dst_row = CONST_CAST(struct ovsdb_row *, ovsdb_table_get_row(weak->dst_table, &weak->dst)); if (dst_row) { @@ -529,7 +529,7 @@ ovsdb_txn_update_weak_refs(struct ovsdb_txn *txn OVS_UNUSED, } /* Insert the weak references added in the new version of the row. */ - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->added_refs) { + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->added_refs) { dst_row = CONST_CAST(struct ovsdb_row *, ovsdb_table_get_row(weak->dst_table, &weak->dst)); @@ -597,7 +597,7 @@ find_and_add_weak_ref(struct ovsdb_txn_row *txn_row, static struct ovsdb_error * OVS_WARN_UNUSED_RESULT assess_weak_refs(struct ovsdb_txn *txn, struct ovsdb_txn_row *txn_row) { - struct ovsdb_weak_ref *weak, *next; + struct ovsdb_weak_ref *weak; struct ovsdb_table *table; struct shash_node *node; @@ -642,7 +642,7 @@ assess_weak_refs(struct ovsdb_txn *txn, struct ovsdb_txn_row *txn_row) /* Collecting all key-value pairs that references deleted rows. */ ovsdb_datum_init_empty(&deleted_refs); - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->deleted_refs) { + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->deleted_refs) { if (column->index == weak->column_idx) { ovsdb_datum_add_unsafe(&deleted_refs, &weak->key, &weak->value, &column->type, NULL); @@ -1094,8 +1094,8 @@ static void ovsdb_txn_destroy_cloned(struct ovsdb_txn *txn) { ovs_assert(!txn->db); - struct ovsdb_txn_table *t, *next_txn_table; - LIST_FOR_EACH_SAFE (t, next_txn_table, node, &txn->txn_tables) { + struct ovsdb_txn_table *t; + LIST_FOR_EACH_SAFE (t, node, &txn->txn_tables) { struct ovsdb_txn_row *r, *next_txn_row; HMAP_FOR_EACH_SAFE (r, next_txn_row, hmap_node, &t->txn_rows) { if (r->old) { @@ -1549,10 +1549,10 @@ for_each_txn_row(struct ovsdb_txn *txn, serial++; do { - struct ovsdb_txn_table *t, *next_txn_table; + struct ovsdb_txn_table *t; any_work = false; - LIST_FOR_EACH_SAFE (t, next_txn_table, node, &txn->txn_tables) { + LIST_FOR_EACH_SAFE (t, node, &txn->txn_tables) { if (t->serial != serial) { t->serial = serial; t->n_processed = 0; @@ -1627,8 +1627,8 @@ ovsdb_txn_history_destroy(struct ovsdb *db) return; } - struct ovsdb_txn_history_node *txn_h_node, *next; - LIST_FOR_EACH_SAFE (txn_h_node, next, node, &db->txn_history) { + struct ovsdb_txn_history_node *txn_h_node; + LIST_FOR_EACH_SAFE (txn_h_node, node, &db->txn_history) { ovs_list_remove(&txn_h_node->node); ovsdb_txn_destroy_cloned(txn_h_node->txn); free(txn_h_node); diff --git a/ovsdb/trigger.c b/ovsdb/trigger.c index 726c138bf..7d3003bca 100644 --- a/ovsdb/trigger.c +++ b/ovsdb/trigger.c @@ -146,14 +146,14 @@ ovsdb_trigger_prereplace_db(struct ovsdb_trigger *trigger) bool ovsdb_trigger_run(struct ovsdb *db, long long int now) { - struct ovsdb_trigger *t, *next; + struct ovsdb_trigger *t; bool run_triggers = db->run_triggers; db->run_triggers_now = db->run_triggers = false; bool disconnect_all = false; - LIST_FOR_EACH_SAFE (t, next, node, &db->triggers) { + LIST_FOR_EACH_SAFE (t, node, &db->triggers) { if (run_triggers || now - t->created >= t->timeout_msec || t->progress || t->txn_forward) { diff --git a/tests/test-list.c b/tests/test-list.c index 30a0be17b..c0e40adff 100644 --- a/tests/test-list.c +++ b/tests/test-list.c @@ -125,7 +125,7 @@ test_list_for_each_safe(void) struct element elements[MAX_ELEMS]; int values[MAX_ELEMS]; struct ovs_list list; - struct element *e, *next; + struct element *e; size_t values_idx, n_remaining; int i; @@ -134,7 +134,7 @@ test_list_for_each_safe(void) i = 0; values_idx = 0; n_remaining = n; - LIST_FOR_EACH_SAFE (e, next, node, &list) { + LIST_FOR_EACH_SAFE (e, node, &list) { assert(i < n); if (pattern & (1ul << i)) { ovs_list_remove(&e->node); diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index ede7f1e61..6771973ae 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -730,12 +730,12 @@ static void bundle_print_errors(struct ovs_list *errors, struct ovs_list *requests, const char *vconn_name) { - struct ofpbuf *error, *next; + struct ofpbuf *error; struct ofpbuf *bmsg; INIT_CONTAINER(bmsg, requests, list_node); - LIST_FOR_EACH_SAFE (error, next, list_node, errors) { + LIST_FOR_EACH_SAFE (error, list_node, errors) { const struct ofp_header *error_oh = error->data; ovs_be32 error_xid = error_oh->xid; enum ofperr ofperr; diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 37cc72d40..812455eea 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1510,13 +1510,13 @@ cmd_add_br(struct ctl_context *ctx) static void del_port(struct vsctl_context *vsctl_ctx, struct vsctl_port *port) { - struct vsctl_iface *iface, *next_iface; + struct vsctl_iface *iface; bridge_delete_port((port->bridge->parent ? port->bridge->parent->br_cfg : port->bridge->br_cfg), port->port_cfg); - LIST_FOR_EACH_SAFE (iface, next_iface, ifaces_node, &port->ifaces) { + LIST_FOR_EACH_SAFE (iface, ifaces_node, &port->ifaces) { del_cached_iface(vsctl_ctx, iface); } del_cached_port(vsctl_ctx, port); @@ -1526,14 +1526,14 @@ static void del_bridge(struct vsctl_context *vsctl_ctx, struct vsctl_bridge *br) { struct vsctl_bridge *child, *next_child; - struct vsctl_port *port, *next_port; + struct vsctl_port *port; const struct ovsrec_flow_sample_collector_set *fscset, *next_fscset; HMAP_FOR_EACH_SAFE (child, next_child, children_node, &br->children) { del_bridge(vsctl_ctx, child); } - LIST_FOR_EACH_SAFE (port, next_port, ports_node, &br->ports) { + LIST_FOR_EACH_SAFE (port, ports_node, &br->ports) { del_port(vsctl_ctx, port); } diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 5223aa897..b1bc51bd5 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -1133,9 +1133,9 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) * whose module was just unloaded via "rmmod", or a virtual NIC for a * VM whose VM was just terminated. */ HMAP_FOR_EACH_SAFE (port, port_next, hmap_node, &br->ports) { - struct iface *iface, *iface_next; + struct iface *iface; - LIST_FOR_EACH_SAFE (iface, iface_next, port_elem, &port->ifaces) { + LIST_FOR_EACH_SAFE (iface, port_elem, &port->ifaces) { if (!sset_contains(&ofproto_ports, iface->name)) { iface_destroy__(iface); } @@ -4341,12 +4341,12 @@ static void bridge_aa_refresh_queued(struct bridge *br) { struct ovs_list *list = xmalloc(sizeof *list); - struct bridge_aa_vlan *node, *next; + struct bridge_aa_vlan *node; ovs_list_init(list); ofproto_aa_vlan_get_queued(br->ofproto, list); - LIST_FOR_EACH_SAFE (node, next, list_node, list) { + LIST_FOR_EACH_SAFE (node, list_node, list) { struct port *port; VLOG_INFO("ifname=%s, vlan=%u, oper=%u", node->port_name, node->vlan, @@ -4387,7 +4387,7 @@ port_create(struct bridge *br, const struct ovsrec_port *cfg) static void port_del_ifaces(struct port *port) { - struct iface *iface, *next; + struct iface *iface; struct sset new_ifaces; size_t i; @@ -4398,7 +4398,7 @@ port_del_ifaces(struct port *port) } /* Get rid of deleted interfaces. */ - LIST_FOR_EACH_SAFE (iface, next, port_elem, &port->ifaces) { + LIST_FOR_EACH_SAFE (iface, port_elem, &port->ifaces) { if (!sset_contains(&new_ifaces, iface->name)) { iface_destroy(iface); } @@ -4412,13 +4412,13 @@ port_destroy(struct port *port) { if (port) { struct bridge *br = port->bridge; - struct iface *iface, *next; + struct iface *iface; if (br->ofproto) { ofproto_bundle_unregister(br->ofproto, port); } - LIST_FOR_EACH_SAFE (iface, next, port_elem, &port->ifaces) { + LIST_FOR_EACH_SAFE (iface, port_elem, &port->ifaces) { iface_destroy__(iface); } diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c index ab552457d..3465d899b 100644 --- a/vtep/vtep-ctl.c +++ b/vtep/vtep-ctl.c @@ -808,9 +808,9 @@ vtep_ctl_context_invalidate_cache(struct ctl_context *ctx) SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_local) { struct vtep_ctl_mcast_mac *mcast_mac = node2->data; - struct vtep_ctl_ploc *ploc, *next_ploc; + struct vtep_ctl_ploc *ploc; - LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node, + LIST_FOR_EACH_SAFE (ploc, locators_node, &mcast_mac->locators) { free(ploc); } @@ -820,9 +820,9 @@ vtep_ctl_context_invalidate_cache(struct ctl_context *ctx) SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_remote) { struct vtep_ctl_mcast_mac *mcast_mac = node2->data; - struct vtep_ctl_ploc *ploc, *next_ploc; + struct vtep_ctl_ploc *ploc; - LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node, + LIST_FOR_EACH_SAFE (ploc, locators_node, &mcast_mac->locators) { free(ploc); } @@ -1229,9 +1229,9 @@ del_port(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_port *port) static void del_pswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_pswitch *ps) { - struct vtep_ctl_port *port, *next_port; + struct vtep_ctl_port *port; - LIST_FOR_EACH_SAFE (port, next_port, ports_node, &ps->ports) { + LIST_FOR_EACH_SAFE (port, ports_node, &ps->ports) { del_port(vtepctl_ctx, port); } From patchwork Mon Jan 24 10:34:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583381 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d12ioKg2; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5wy5xsgz9t0k for ; Mon, 24 Jan 2022 21:35:46 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 33A6541707; Mon, 24 Jan 2022 10:35:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id k7kCCuEzOyrd; Mon, 24 Jan 2022 10:35:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id E94D841726; Mon, 24 Jan 2022 10:35:36 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7419BC0081; Mon, 24 Jan 2022 10:35:35 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1F6DBC007D for ; Mon, 24 Jan 2022 10:35:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 31948408D3 for ; Mon, 24 Jan 2022 10:35:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nBw0OK4BIvGB for ; Mon, 24 Jan 2022 10:35:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id E95D340591 for ; Mon, 24 Jan 2022 10:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=71ufgZG8cWqzSSysmRfm2CeEWa9i+QuBpWqjfzqw4f4=; b=d12ioKg2Vc0M4g0UmI1FyouYuTHG6HtxwGqq2A2T5FDMkcBhZxv4w7EEIw+6/M27BLH5im RhyftdCqy/ixklKYcx0gl+r29wsChIgilFc63OZ2DBaU8Hc5s5nc7HsQp+3nc2ojIQC6oD zWIWsh1se7eDRBxZ1e1QhwfMggUJpfc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-32-LySZcMGJOme2rl5qxq0fEA-1; Mon, 24 Jan 2022 05:35:24 -0500 X-MC-Unique: LySZcMGJOme2rl5qxq0fEA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4BBBC1083F62; Mon, 24 Jan 2022 10:35:23 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39A687A235; Mon, 24 Jan 2022 10:35:21 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:38 +0100 Message-Id: <20220124103445.2459400-7-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 06/13] hmap: use multi-variable helpers for hmap loops X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Rewrite hmap's loops using multi-variable helpers. For safe loops, we keep the (now unused) NEXT variable to keep backwards compatibility. Signed-off-by: Adrian Moreno --- include/openvswitch/hmap.h | 61 +++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/include/openvswitch/hmap.h b/include/openvswitch/hmap.h index 4e001cc69..ad41656a9 100644 --- a/include/openvswitch/hmap.h +++ b/include/openvswitch/hmap.h @@ -134,17 +134,17 @@ struct hmap_node *hmap_random_node(const struct hmap *); * without using 'break', NODE will be NULL. This is true for all of the * HMAP_FOR_EACH_*() macros. */ -#define HMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HMAP) \ - for (INIT_CONTAINER(NODE, hmap_first_with_hash(HMAP, HASH), MEMBER); \ - (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) \ - || ((NODE = NULL), false); \ - ASSIGN_CONTAINER(NODE, hmap_next_with_hash(&(NODE)->MEMBER), \ - MEMBER)) -#define HMAP_FOR_EACH_IN_BUCKET(NODE, MEMBER, HASH, HMAP) \ - for (INIT_CONTAINER(NODE, hmap_first_in_bucket(HMAP, HASH), MEMBER); \ - (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) \ - || ((NODE = NULL), false); \ - ASSIGN_CONTAINER(NODE, hmap_next_in_bucket(&(NODE)->MEMBER), MEMBER)) +#define HMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HMAP) \ + for (INIT_MULTIVAR(NODE, MEMBER, hmap_first_with_hash(HMAP, HASH)); \ + CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(NODE) = hmap_next_with_hash(ITER_VAR(NODE)),\ + NODE)) + +#define HMAP_FOR_EACH_IN_BUCKET(NODE, MEMBER, HASH, HMAP) \ + for (INIT_MULTIVAR(NODE, MEMBER, hmap_first_in_bucket(HMAP, HASH)); \ + CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(NODE) = hmap_next_in_bucket(ITER_VAR(NODE)),\ + NODE)) static inline struct hmap_node *hmap_first_with_hash(const struct hmap *, size_t hash); @@ -170,33 +170,34 @@ bool hmap_contains(const struct hmap *, const struct hmap_node *); /* Iterates through every node in HMAP. */ #define HMAP_FOR_EACH(NODE, MEMBER, HMAP) \ HMAP_FOR_EACH_INIT(NODE, MEMBER, HMAP, (void) 0) -#define HMAP_FOR_EACH_INIT(NODE, MEMBER, HMAP, ...) \ - for (INIT_CONTAINER(NODE, hmap_first(HMAP), MEMBER), __VA_ARGS__; \ - (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) \ - || ((NODE = NULL), false); \ - ASSIGN_CONTAINER(NODE, hmap_next(HMAP, &(NODE)->MEMBER), MEMBER)) +#define HMAP_FOR_EACH_INIT(NODE, MEMBER, HMAP, ...) \ + for (INIT_MULTIVAR_EXP(NODE, MEMBER, hmap_first(HMAP), __VA_ARGS__); \ + CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(NODE) = hmap_next(HMAP, ITER_VAR(NODE)), \ + NODE)) /* Safe when NODE may be freed (not needed when NODE may be removed from the * hash map but its members remain accessible and intact). */ #define HMAP_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HMAP) \ - HMAP_FOR_EACH_SAFE_INIT(NODE, NEXT, MEMBER, HMAP, (void) 0) -#define HMAP_FOR_EACH_SAFE_INIT(NODE, NEXT, MEMBER, HMAP, ...) \ - for (INIT_CONTAINER(NODE, hmap_first(HMAP), MEMBER), __VA_ARGS__; \ - ((NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) \ - || ((NODE = NULL), false) \ - ? INIT_CONTAINER(NEXT, hmap_next(HMAP, &(NODE)->MEMBER), MEMBER), 1 \ - : 0); \ - (NODE) = (NEXT)) + HMAP_FOR_EACH_SAFE_INIT(NODE, NEXT, MEMBER, HMAP, (void) NEXT) +#define HMAP_FOR_EACH_SAFE_INIT(NODE, NEXT, MEMBER, HMAP, ...) \ + for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, hmap_first(HMAP), (void) NEXT, \ + __VA_ARGS__); \ + CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL, \ + ITER_NEXT_VAR(NODE) = hmap_next(HMAP, ITER_VAR(NODE)),\ + NODE, MEMBER); \ + UPDATE_MULTIVAR_SAFE(NODE)) /* Continues an iteration from just after NODE. */ #define HMAP_FOR_EACH_CONTINUE(NODE, MEMBER, HMAP) \ HMAP_FOR_EACH_CONTINUE_INIT(NODE, MEMBER, HMAP, (void) 0) -#define HMAP_FOR_EACH_CONTINUE_INIT(NODE, MEMBER, HMAP, ...) \ - for (ASSIGN_CONTAINER(NODE, hmap_next(HMAP, &(NODE)->MEMBER), MEMBER), \ - __VA_ARGS__; \ - (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) \ - || ((NODE = NULL), false); \ - ASSIGN_CONTAINER(NODE, hmap_next(HMAP, &(NODE)->MEMBER), MEMBER)) +#define HMAP_FOR_EACH_CONTINUE_INIT(NODE, MEMBER, HMAP, ...) \ + for (INIT_MULTIVAR_EXP(NODE, MEMBER, hmap_next(HMAP, &(NODE)->MEMBER), \ + __VA_ARGS__); \ + CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(NODE) = hmap_next(HMAP, ITER_VAR(NODE)), \ + NODE)) + static inline struct hmap_node * hmap_pop_helper__(struct hmap *hmap, size_t *bucket) { From patchwork Mon Jan 24 10:34:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583382 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KVeQAHbr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5x52Kx8z9t0k for ; Mon, 24 Jan 2022 21:35:53 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id D96514166C; Mon, 24 Jan 2022 10:35:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2FV8ADTDVFSy; Mon, 24 Jan 2022 10:35:49 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 8F2B541742; Mon, 24 Jan 2022 10:35:45 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5C685C0039; Mon, 24 Jan 2022 10:35:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0FF20C0039 for ; Mon, 24 Jan 2022 10:35:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 0AF0E83FAD for ; Mon, 24 Jan 2022 10:35:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rPkBVSxZDSEs for ; Mon, 24 Jan 2022 10:35:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id D254983F90 for ; Mon, 24 Jan 2022 10:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sFm6QfVriICmmK479+P/a6xUjMLIUVybdze9QYI1HY0=; b=KVeQAHbrK5lP4bn1gIOJ4nRF4bASJcYeiG67Cgo3UxK0UTRUqbymB+EUyeO5X1xSF8fCDp yyro3idAFknAVXmZ3RRl81UqS2ps6DC9kXqY+aMd+oHbFNDJ/RDcidVIESt+u4vvV4GWfW k9JKJoUHMLMeO80NYwul133+XoNk3qg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-178-ibt8SDNiMcaYXew2Rs7rsw-1; Mon, 24 Jan 2022 05:35:26 -0500 X-MC-Unique: ibt8SDNiMcaYXew2Rs7rsw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80B8136393; Mon, 24 Jan 2022 10:35:25 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A54247A240; Mon, 24 Jan 2022 10:35:23 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:39 +0100 Message-Id: <20220124103445.2459400-8-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 07/13] hmap: implement UB-safe hmap pop iterator X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" HMAP_FOR_EACH_POP iterator has an additional difficulty, which is the use of two iterator variables of different types. In order to re-write this loop in a UB-safe manner, create a iterator struct to be used as loop variable. Signed-off-by: Adrian Moreno --- include/openvswitch/hmap.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/include/openvswitch/hmap.h b/include/openvswitch/hmap.h index ad41656a9..71b0f3a96 100644 --- a/include/openvswitch/hmap.h +++ b/include/openvswitch/hmap.h @@ -199,26 +199,33 @@ bool hmap_contains(const struct hmap *, const struct hmap_node *); NODE)) -static inline struct hmap_node * -hmap_pop_helper__(struct hmap *hmap, size_t *bucket) { +struct hmap_pop_helper_iter__ { + size_t bucket; + struct hmap_node *node; +}; + +static inline void +hmap_pop_helper__(struct hmap *hmap, struct hmap_pop_helper_iter__ *iter) { - for (; *bucket <= hmap->mask; (*bucket)++) { - struct hmap_node *node = hmap->buckets[*bucket]; + for (; iter->bucket <= hmap->mask; (iter->bucket)++) { + struct hmap_node *node = hmap->buckets[iter->bucket]; if (node) { hmap_remove(hmap, node); - return node; + iter->node = node; + return; } } - - return NULL; + iter->node = NULL; } -#define HMAP_FOR_EACH_POP(NODE, MEMBER, HMAP) \ - for (size_t bucket__ = 0; \ - INIT_CONTAINER(NODE, hmap_pop_helper__(HMAP, &bucket__), MEMBER), \ - (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) \ - || ((NODE = NULL), false);) +#define HMAP_FOR_EACH_POP(NODE, MEMBER, HMAP) \ + for (struct hmap_pop_helper_iter__ ITER_VAR(NODE) = { 0, NULL }; \ + hmap_pop_helper__(HMAP, &ITER_VAR(NODE)), \ + (ITER_VAR(NODE).node != NULL) ? \ + (((NODE) = OBJECT_CONTAINING(ITER_VAR(NODE).node, \ + NODE, MEMBER)),1): \ + (((NODE) = NULL), 0);) static inline struct hmap_node *hmap_first(const struct hmap *); static inline struct hmap_node *hmap_next(const struct hmap *, From patchwork Mon Jan 24 10:34:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583388 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BQ51fdSW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5xw5xQrz9t0k for ; Mon, 24 Jan 2022 21:36:36 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 5BCC240AC9; Mon, 24 Jan 2022 10:36:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1_g2q6nIJJbV; Mon, 24 Jan 2022 10:36:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 4CAB540A9D; Mon, 24 Jan 2022 10:36:29 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0EC47C0072; Mon, 24 Jan 2022 10:36:29 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1ED80C007B for ; Mon, 24 Jan 2022 10:36:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 6880060E4B for ; Mon, 24 Jan 2022 10:35:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wDEyoP74nUVb for ; Mon, 24 Jan 2022 10:35:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id B2BDC60E7B for ; Mon, 24 Jan 2022 10:35:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y1p2Z3YGNO+rg1DS9X4fiG2+77zzhxuQN0+A8gCJdqA=; b=BQ51fdSWYVcMP0fzvoPvlozWTjsXWuAyKkubsDpoY3l0I10j2cvdyS/4Kf/+961Awe22sM Ecyqn4sQ3c4H55znRp+/pJwc3O48+DrDwUk3pGzTcY4VzUDs3xMzasT6eW8PCPeon2SSbg 1gsbGQZlKZgUJ24sEbRmf8LQAmGABck= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-gAmqXbPeMEe03hUC_DE6lQ-1; Mon, 24 Jan 2022 05:35:29 -0500 X-MC-Unique: gAmqXbPeMEe03hUC_DE6lQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1843136393; Mon, 24 Jan 2022 10:35:28 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7BF17A235; Mon, 24 Jan 2022 10:35:25 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:40 +0100 Message-Id: <20220124103445.2459400-9-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 08/13] hmap: remove the next variable in safe loops X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Apart from being safer from the point of view of potential undefined behavior, the multi-variable version of the safe iterators have the benefit of not requiring the declaration of an external variable to hold the next position. This patch removes the NEXT variable from HMAP_FOR_ALL_SAFE macro and all of its callers and wrappers. Signed-off-by: Adrian Moreno --- include/openvswitch/hmap.h | 9 +++--- include/openvswitch/shash.h | 5 ++-- lib/cfm.c | 4 +-- lib/classifier.c | 4 +-- lib/dns-resolve.c | 4 +-- lib/dpif-netdev.c | 19 ++++++------ lib/hmapx.c | 4 +-- lib/hmapx.h | 5 ++-- lib/json.c | 4 +-- lib/lacp.c | 4 +-- lib/mac-learning.c | 4 +-- lib/namemap.c | 4 +-- lib/netdev-dpdk.c | 4 +-- lib/netdev-linux.c | 4 +-- lib/netdev-offload-tc.c | 4 +-- lib/ofp-msgs.c | 4 +-- lib/ovsdb-cs.c | 12 ++++---- lib/ovsdb-idl.c | 16 +++++------ lib/ovsdb-map-op.c | 4 +-- lib/ovsdb-set-op.c | 4 +-- lib/pcap-file.c | 4 +-- lib/perf-counter.c | 4 +-- lib/poll-loop.c | 4 +-- lib/seq.c | 4 +-- lib/shash.c | 8 +++--- lib/simap.c | 4 +-- lib/simap.h | 5 ++-- lib/smap.c | 4 +-- lib/smap.h | 5 ++-- lib/stopwatch.c | 4 +-- ofproto/bond.c | 4 +-- ofproto/connmgr.c | 20 ++++++------- ofproto/in-band.c | 4 +-- ofproto/netflow.c | 8 +++--- ofproto/ofproto-dpif-ipfix.c | 8 +++--- ofproto/ofproto-dpif-sflow.c | 4 +-- ofproto/ofproto-dpif-xlate.c | 8 +++--- ofproto/ofproto-dpif.c | 4 +-- ofproto/ofproto.c | 16 +++++------ ovsdb/condition.c | 8 +++--- ovsdb/jsonrpc-server.c | 24 ++++++++-------- ovsdb/monitor.c | 12 ++++---- ovsdb/ovsdb-server.c | 11 ++++--- ovsdb/ovsdb-tool.c | 7 ++--- ovsdb/query.c | 4 +-- ovsdb/raft-private.c | 4 +-- ovsdb/raft.c | 18 ++++++------ ovsdb/relay.c | 4 +-- ovsdb/replication.c | 8 +++--- ovsdb/table.c | 4 +-- ovsdb/transaction-forward.c | 4 +-- ovsdb/transaction.c | 8 +++--- tests/test-cmap.c | 4 +-- tests/test-hmap.c | 4 +-- utilities/ovs-vsctl.c | 4 +-- vswitchd/bridge.c | 56 ++++++++++++++++++------------------ vtep/vtep-ctl.c | 6 ++-- 57 files changed, 213 insertions(+), 221 deletions(-) diff --git a/include/openvswitch/hmap.h b/include/openvswitch/hmap.h index 71b0f3a96..dc1a425f9 100644 --- a/include/openvswitch/hmap.h +++ b/include/openvswitch/hmap.h @@ -178,11 +178,10 @@ bool hmap_contains(const struct hmap *, const struct hmap_node *); /* Safe when NODE may be freed (not needed when NODE may be removed from the * hash map but its members remain accessible and intact). */ -#define HMAP_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HMAP) \ - HMAP_FOR_EACH_SAFE_INIT(NODE, NEXT, MEMBER, HMAP, (void) NEXT) -#define HMAP_FOR_EACH_SAFE_INIT(NODE, NEXT, MEMBER, HMAP, ...) \ - for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, hmap_first(HMAP), (void) NEXT, \ - __VA_ARGS__); \ +#define HMAP_FOR_EACH_SAFE(NODE, MEMBER, HMAP) \ + HMAP_FOR_EACH_SAFE_INIT(NODE, MEMBER, HMAP, (void) 0) +#define HMAP_FOR_EACH_SAFE_INIT(NODE, MEMBER, HMAP, ...) \ + for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, hmap_first(HMAP), __VA_ARGS__); \ CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL, \ ITER_NEXT_VAR(NODE) = hmap_next(HMAP, ITER_VAR(NODE)),\ NODE, MEMBER); \ diff --git a/include/openvswitch/shash.h b/include/openvswitch/shash.h index c249e13e1..4688efbbc 100644 --- a/include/openvswitch/shash.h +++ b/include/openvswitch/shash.h @@ -41,11 +41,10 @@ struct shash { BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \ BUILD_ASSERT_TYPE(SHASH, struct shash *)) -#define SHASH_FOR_EACH_SAFE(SHASH_NODE, NEXT, SHASH) \ +#define SHASH_FOR_EACH_SAFE(SHASH_NODE, SHASH) \ HMAP_FOR_EACH_SAFE_INIT ( \ - SHASH_NODE, NEXT, node, &(SHASH)->map, \ + SHASH_NODE, node, &(SHASH)->map, \ BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \ - BUILD_ASSERT_TYPE(NEXT, struct shash_node *), \ BUILD_ASSERT_TYPE(SHASH, struct shash *)) void shash_init(struct shash *); diff --git a/lib/cfm.c b/lib/cfm.c index cc43e70e3..c3742f3de 100644 --- a/lib/cfm.c +++ b/lib/cfm.c @@ -416,7 +416,7 @@ cfm_run(struct cfm *cfm) OVS_EXCLUDED(mutex) ovs_mutex_lock(&mutex); if (timer_expired(&cfm->fault_timer)) { long long int interval = cfm_fault_interval(cfm); - struct remote_mp *rmp, *rmp_next; + struct remote_mp *rmp; enum cfm_fault_reason old_cfm_fault = cfm->fault; uint64_t old_flap_count = cfm->flap_count; int old_health = cfm->health; @@ -475,7 +475,7 @@ cfm_run(struct cfm *cfm) OVS_EXCLUDED(mutex) cfm->rx_packets = rx_packets; } - HMAP_FOR_EACH_SAFE (rmp, rmp_next, node, &cfm->remote_mps) { + HMAP_FOR_EACH_SAFE (rmp, node, &cfm->remote_mps) { if (!rmp->recv) { VLOG_INFO("%s: Received no CCM from RMP %"PRIu64" in the last" " %lldms", cfm->name, rmp->mpid, diff --git a/lib/classifier.c b/lib/classifier.c index c4790ee6b..0a89626cc 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -916,9 +916,9 @@ free_conjunctive_matches(struct hmap *matches, struct conjunctive_match *cm_stubs, size_t n_cm_stubs) { if (hmap_count(matches) > n_cm_stubs) { - struct conjunctive_match *cm, *next; + struct conjunctive_match *cm; - HMAP_FOR_EACH_SAFE (cm, next, hmap_node, matches) { + HMAP_FOR_EACH_SAFE (cm, hmap_node, matches) { if (!(cm >= cm_stubs && cm < &cm_stubs[n_cm_stubs])) { free(cm); } diff --git a/lib/dns-resolve.c b/lib/dns-resolve.c index d34451434..a31e19c07 100644 --- a/lib/dns-resolve.c +++ b/lib/dns-resolve.c @@ -189,8 +189,8 @@ dns_resolve_destroy(void) ub_ctx_delete(ub_ctx__); ub_ctx__ = NULL; - struct resolve_request *req, *next; - HMAP_FOR_EACH_SAFE (req, next, hmap_node, &all_reqs__) { + struct resolve_request *req; + HMAP_FOR_EACH_SAFE (req, hmap_node, &all_reqs__) { ub_resolve_free(req->ub_result); free(req->addr); free(req->name); diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 1efeab622..76332925d 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1862,13 +1862,13 @@ static void dp_netdev_free(struct dp_netdev *dp) OVS_REQUIRES(dp_netdev_mutex) { - struct dp_netdev_port *port, *next; + struct dp_netdev_port *port; struct tx_bond *bond; shash_find_and_delete(&dp_netdevs, dp->name); ovs_mutex_lock(&dp->port_mutex); - HMAP_FOR_EACH_SAFE (port, next, node, &dp->ports) { + HMAP_FOR_EACH_SAFE (port, node, &dp->ports) { do_del_port(dp, port); } ovs_mutex_unlock(&dp->port_mutex); @@ -5905,11 +5905,11 @@ pmd_remove_stale_ports(struct dp_netdev *dp, OVS_EXCLUDED(pmd->port_mutex) OVS_REQUIRES(dp->port_mutex) { - struct rxq_poll *poll, *poll_next; - struct tx_port *tx, *tx_next; + struct rxq_poll *poll; + struct tx_port *tx; ovs_mutex_lock(&pmd->port_mutex); - HMAP_FOR_EACH_SAFE (poll, poll_next, node, &pmd->poll_list) { + HMAP_FOR_EACH_SAFE (poll, node, &pmd->poll_list) { struct dp_netdev_port *port = poll->rxq->port; if (port->need_reconfigure @@ -5917,7 +5917,7 @@ pmd_remove_stale_ports(struct dp_netdev *dp, dp_netdev_del_rxq_from_pmd(pmd, poll); } } - HMAP_FOR_EACH_SAFE (tx, tx_next, node, &pmd->tx_ports) { + HMAP_FOR_EACH_SAFE (tx, node, &pmd->tx_ports) { struct dp_netdev_port *port = tx->port; if (port->need_reconfigure @@ -5990,8 +5990,7 @@ reconfigure_datapath(struct dp_netdev *dp) /* We only reconfigure the ports that we determined above, because they're * not being used by any pmd thread at the moment. If a port fails to * reconfigure we remove it from the datapath. */ - struct dp_netdev_port *next_port; - HMAP_FOR_EACH_SAFE (port, next_port, node, &dp->ports) { + HMAP_FOR_EACH_SAFE (port, node, &dp->ports) { int err; if (!port->need_reconfigure) { @@ -6039,10 +6038,10 @@ reconfigure_datapath(struct dp_netdev *dp) } CMAP_FOR_EACH (pmd, node, &dp->poll_threads) { - struct rxq_poll *poll, *poll_next; + struct rxq_poll *poll; ovs_mutex_lock(&pmd->port_mutex); - HMAP_FOR_EACH_SAFE (poll, poll_next, node, &pmd->poll_list) { + HMAP_FOR_EACH_SAFE (poll, node, &pmd->poll_list) { if (poll->rxq->pmd != pmd) { dp_netdev_del_rxq_from_pmd(pmd, poll); diff --git a/lib/hmapx.c b/lib/hmapx.c index eadfe640a..68192fc2c 100644 --- a/lib/hmapx.c +++ b/lib/hmapx.c @@ -123,9 +123,9 @@ hmapx_add_assert(struct hmapx *map, void *data) void hmapx_clear(struct hmapx *map) { - struct hmapx_node *node, *next; + struct hmapx_node *node; - HMAPX_FOR_EACH_SAFE (node, next, map) { + HMAPX_FOR_EACH_SAFE (node, map) { hmapx_delete(map, node); } } diff --git a/lib/hmapx.h b/lib/hmapx.h index 06a6bbe67..5f9ed2664 100644 --- a/lib/hmapx.h +++ b/lib/hmapx.h @@ -67,10 +67,9 @@ bool hmapx_equals(const struct hmapx *, const struct hmapx *); /* Safe when NODE may be freed (not needed when NODE may be removed from the * hash map but its members remain accessible and intact). */ -#define HMAPX_FOR_EACH_SAFE(NODE, NEXT, HMAPX) \ - HMAP_FOR_EACH_SAFE_INIT(NODE, NEXT, hmap_node, &(HMAPX)->map, \ +#define HMAPX_FOR_EACH_SAFE(NODE, HMAPX) \ + HMAP_FOR_EACH_SAFE_INIT(NODE, hmap_node, &(HMAPX)->map, \ BUILD_ASSERT_TYPE(NODE, struct hmapx_node *), \ - BUILD_ASSERT_TYPE(NEXT, struct hmapx_node *), \ BUILD_ASSERT_TYPE(HMAPX, struct hmapx *)) #endif /* hmapx.h */ diff --git a/lib/json.c b/lib/json.c index 720c73d94..042aab83b 100644 --- a/lib/json.c +++ b/lib/json.c @@ -397,9 +397,9 @@ json_destroy__(struct json *json) static void json_destroy_object(struct shash *object) { - struct shash_node *node, *next; + struct shash_node *node; - SHASH_FOR_EACH_SAFE (node, next, object) { + SHASH_FOR_EACH_SAFE (node, object) { struct json *value = node->data; json_destroy(value); diff --git a/lib/lacp.c b/lib/lacp.c index 89d711225..3252f17eb 100644 --- a/lib/lacp.c +++ b/lib/lacp.c @@ -280,10 +280,10 @@ void lacp_unref(struct lacp *lacp) OVS_EXCLUDED(mutex) { if (lacp && ovs_refcount_unref_relaxed(&lacp->ref_cnt) == 1) { - struct member *member, *next; + struct member *member; lacp_lock(); - HMAP_FOR_EACH_SAFE (member, next, node, &lacp->members) { + HMAP_FOR_EACH_SAFE (member, node, &lacp->members) { member_destroy(member); } diff --git a/lib/mac-learning.c b/lib/mac-learning.c index 3fcd7d9b7..a60794fb2 100644 --- a/lib/mac-learning.c +++ b/lib/mac-learning.c @@ -244,10 +244,10 @@ void mac_learning_unref(struct mac_learning *ml) { if (ml && ovs_refcount_unref(&ml->ref_cnt) == 1) { - struct mac_entry *e, *next; + struct mac_entry *e; ovs_rwlock_wrlock(&ml->rwlock); - HMAP_FOR_EACH_SAFE (e, next, hmap_node, &ml->table) { + HMAP_FOR_EACH_SAFE (e, hmap_node, &ml->table) { mac_learning_expire(ml, e); } hmap_destroy(&ml->table); diff --git a/lib/namemap.c b/lib/namemap.c index 785cda4c2..dd317ea52 100644 --- a/lib/namemap.c +++ b/lib/namemap.c @@ -90,9 +90,9 @@ void namemap_destroy(struct namemap *map) { if (map) { - struct namemap_node *node, *next; + struct namemap_node *node; - HMAP_FOR_EACH_SAFE (node, next, name_node, &map->by_name) { + HMAP_FOR_EACH_SAFE (node, name_node, &map->by_name) { hmap_remove(&map->by_name, &node->name_node); hmap_remove(&map->by_number, &node->number_node); free(node->name); diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index ef9a05d67..1ef4f4a57 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -4711,11 +4711,11 @@ trtcm_policer_qos_construct(const struct smap *details, static void trtcm_policer_qos_destruct(struct qos_conf *conf) { - struct trtcm_policer_queue *queue, *next_queue; + struct trtcm_policer_queue *queue; struct trtcm_policer *policer = CONTAINER_OF(conf, struct trtcm_policer, qos_conf); - HMAP_FOR_EACH_SAFE (queue, next_queue, hmap_node, &policer->queues) { + HMAP_FOR_EACH_SAFE (queue, hmap_node, &policer->queues) { hmap_remove(&policer->queues, &queue->hmap_node); free(queue); } diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 97bd21be4..4d6967b52 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -5321,11 +5321,11 @@ static void hfsc_tc_destroy(struct tc *tc) { struct hfsc *hfsc; - struct hfsc_class *hc, *next; + struct hfsc_class *hc; hfsc = CONTAINER_OF(tc, struct hfsc, tc); - HMAP_FOR_EACH_SAFE (hc, next, tc_queue.hmap_node, &hfsc->tc.queues) { + HMAP_FOR_EACH_SAFE (hc, tc_queue.hmap_node, &hfsc->tc.queues) { hmap_remove(&hfsc->tc.queues, &hc->tc_queue.hmap_node); free(hc); } diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 9845e8d3f..1af8ca3c9 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -417,11 +417,11 @@ delete_chains_from_netdev(struct netdev *netdev, struct tcf_id *id) static int netdev_tc_flow_flush(struct netdev *netdev) { - struct ufid_tc_data *data, *next; + struct ufid_tc_data *data; int err; ovs_mutex_lock(&ufid_lock); - HMAP_FOR_EACH_SAFE (data, next, tc_to_ufid_node, &tc_to_ufid) { + HMAP_FOR_EACH_SAFE (data, tc_to_ufid_node, &tc_to_ufid) { if (data->netdev != netdev) { continue; } diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c index 8f969ee59..93aa81297 100644 --- a/lib/ofp-msgs.c +++ b/lib/ofp-msgs.c @@ -1123,8 +1123,8 @@ ofpmp_partial_error(struct hmap *assembler, struct ofpmp_partial *p, void ofpmp_assembler_clear(struct hmap *assembler) { - struct ofpmp_partial *p, *next; - HMAP_FOR_EACH_SAFE (p, next, hmap_node, assembler) { + struct ofpmp_partial *p; + HMAP_FOR_EACH_SAFE (p, hmap_node, assembler) { ofpmp_partial_destroy(assembler, p); } } diff --git a/lib/ovsdb-cs.c b/lib/ovsdb-cs.c index fcb6fe1b3..ba35735d9 100644 --- a/lib/ovsdb-cs.c +++ b/lib/ovsdb-cs.c @@ -900,8 +900,8 @@ ovsdb_cs_db_get_table(struct ovsdb_cs_db *db, const char *table) static void ovsdb_cs_db_destroy_tables(struct ovsdb_cs_db *db) { - struct ovsdb_cs_db_table *table, *next; - HMAP_FOR_EACH_SAFE (table, next, hmap_node, &db->tables) { + struct ovsdb_cs_db_table *table; + HMAP_FOR_EACH_SAFE (table, hmap_node, &db->tables) { json_destroy(table->ack_cond); json_destroy(table->req_cond); json_destroy(table->new_cond); @@ -1777,8 +1777,8 @@ ovsdb_cs_update_server_row(struct server_row *row, static void ovsdb_cs_clear_server_rows(struct ovsdb_cs *cs) { - struct server_row *row, *next; - HMAP_FOR_EACH_SAFE (row, next, hmap_node, &cs->server_rows) { + struct server_row *row; + HMAP_FOR_EACH_SAFE (row, hmap_node, &cs->server_rows) { ovsdb_cs_delete_server_row(cs, row); } } @@ -2112,9 +2112,9 @@ void ovsdb_cs_free_schema(struct shash *schema) { if (schema) { - struct shash_node *node, *next; + struct shash_node *node; - SHASH_FOR_EACH_SAFE (node, next, schema) { + SHASH_FOR_EACH_SAFE (node, schema) { struct sset *sset = node->data; sset_destroy(sset); free(sset); diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index b0e03ef1f..cecc0f51b 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -389,13 +389,13 @@ ovsdb_idl_clear(struct ovsdb_idl *db) */ for (size_t i = 0; i < db->class_->n_tables; i++) { struct ovsdb_idl_table *table = &db->tables[i]; - struct ovsdb_idl_row *row, *next_row; + struct ovsdb_idl_row *row; if (hmap_is_empty(&table->rows)) { continue; } - HMAP_FOR_EACH_SAFE (row, next_row, hmap_node, &table->rows) { + HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) { struct ovsdb_idl_arc *arc; if (!ovsdb_idl_row_is_orphan(row)) { @@ -1041,8 +1041,8 @@ ovsdb_idl_condition_destroy(struct ovsdb_idl_condition *cond) void ovsdb_idl_condition_clear(struct ovsdb_idl_condition *cond) { - struct ovsdb_idl_clause *clause, *next; - HMAP_FOR_EACH_SAFE (clause, next, hmap_node, &cond->clauses) { + struct ovsdb_idl_clause *clause; + HMAP_FOR_EACH_SAFE (clause, hmap_node, &cond->clauses) { hmap_remove(&cond->clauses, &clause->hmap_node); ovsdb_idl_clause_destroy(clause); } @@ -2729,7 +2729,7 @@ ovsdb_idl_txn_increment(struct ovsdb_idl_txn *txn, void ovsdb_idl_txn_destroy(struct ovsdb_idl_txn *txn) { - struct ovsdb_idl_txn_insert *insert, *next; + struct ovsdb_idl_txn_insert *insert; if (txn->status == TXN_INCOMPLETE) { ovsdb_cs_forget_transaction(txn->idl->cs, txn->request_id); @@ -2739,7 +2739,7 @@ ovsdb_idl_txn_destroy(struct ovsdb_idl_txn *txn) ovsdb_idl_txn_abort(txn); ds_destroy(&txn->comment); free(txn->error); - HMAP_FOR_EACH_SAFE (insert, next, hmap_node, &txn->inserted_rows) { + HMAP_FOR_EACH_SAFE (insert, hmap_node, &txn->inserted_rows) { free(insert); } hmap_destroy(&txn->inserted_rows); @@ -2824,7 +2824,7 @@ substitute_uuids(struct json *json, const struct ovsdb_idl_txn *txn) static void ovsdb_idl_txn_disassemble(struct ovsdb_idl_txn *txn) { - struct ovsdb_idl_row *row, *next; + struct ovsdb_idl_row *row; /* This must happen early. Otherwise, ovsdb_idl_row_parse() will call an * ovsdb_idl_column's 'parse' function, which will call @@ -2832,7 +2832,7 @@ ovsdb_idl_txn_disassemble(struct ovsdb_idl_txn *txn) * transaction and fail to update the graph. */ txn->idl->txn = NULL; - HMAP_FOR_EACH_SAFE (row, next, txn_node, &txn->txn_rows) { + HMAP_FOR_EACH_SAFE (row, txn_node, &txn->txn_rows) { enum { INSERTED, MODIFIED, DELETED } op = (!row->new_datum ? DELETED : !row->old_datum ? INSERTED diff --git a/lib/ovsdb-map-op.c b/lib/ovsdb-map-op.c index 7b90ba84f..795066e8e 100644 --- a/lib/ovsdb-map-op.c +++ b/lib/ovsdb-map-op.c @@ -91,8 +91,8 @@ map_op_list_create(void) void map_op_list_destroy(struct map_op_list *list, const struct ovsdb_type *type) { - struct map_op *map_op, *next; - HMAP_FOR_EACH_SAFE (map_op, next, node, &list->hmap) { + struct map_op *map_op; + HMAP_FOR_EACH_SAFE (map_op, node, &list->hmap) { map_op_destroy(map_op, type); } hmap_destroy(&list->hmap); diff --git a/lib/ovsdb-set-op.c b/lib/ovsdb-set-op.c index 62c462118..321043282 100644 --- a/lib/ovsdb-set-op.c +++ b/lib/ovsdb-set-op.c @@ -90,8 +90,8 @@ set_op_list_create(void) void set_op_list_destroy(struct set_op_list *list, const struct ovsdb_type *type) { - struct set_op *set_op, *next; - HMAP_FOR_EACH_SAFE (set_op, next, node, &list->hmap) { + struct set_op *set_op; + HMAP_FOR_EACH_SAFE (set_op, node, &list->hmap) { set_op_destroy(set_op, type); } hmap_destroy(&list->hmap); diff --git a/lib/pcap-file.c b/lib/pcap-file.c index 41835f6f4..3ed7ea488 100644 --- a/lib/pcap-file.c +++ b/lib/pcap-file.c @@ -344,9 +344,9 @@ tcp_reader_open(void) void tcp_reader_close(struct tcp_reader *r) { - struct tcp_stream *stream, *next_stream; + struct tcp_stream *stream; - HMAP_FOR_EACH_SAFE (stream, next_stream, hmap_node, &r->streams) { + HMAP_FOR_EACH_SAFE (stream, hmap_node, &r->streams) { tcp_stream_destroy(r, stream); } hmap_destroy(&r->streams); diff --git a/lib/perf-counter.c b/lib/perf-counter.c index e4eca58d0..6952fcb59 100644 --- a/lib/perf-counter.c +++ b/lib/perf-counter.c @@ -178,14 +178,14 @@ perf_counters_clear(void) void perf_counters_destroy(void) { - struct shash_node *node, *next; + struct shash_node *node; if (fd__ != -1) { ioctl(fd__, PERF_EVENT_IOC_DISABLE, 0); close(fd__); } - SHASH_FOR_EACH_SAFE (node, next, &perf_counters) { + SHASH_FOR_EACH_SAFE (node, &perf_counters) { shash_delete(&perf_counters, node); } diff --git a/lib/poll-loop.c b/lib/poll-loop.c index 4e751ff2c..70fabeb8a 100644 --- a/lib/poll-loop.c +++ b/lib/poll-loop.c @@ -298,9 +298,9 @@ log_wakeup(const char *where, const struct pollfd *pollfd, int timeout) static void free_poll_nodes(struct poll_loop *loop) { - struct poll_node *node, *next; + struct poll_node *node; - HMAP_FOR_EACH_SAFE (node, next, hmap_node, &loop->poll_nodes) { + HMAP_FOR_EACH_SAFE (node, hmap_node, &loop->poll_nodes) { hmap_remove(&loop->poll_nodes, &node->hmap_node); #ifdef _WIN32 if (node->wevent && node->pollfd.fd) { diff --git a/lib/seq.c b/lib/seq.c index 2434ccb5d..99e5bf8bd 100644 --- a/lib/seq.c +++ b/lib/seq.c @@ -319,9 +319,9 @@ static void seq_wake_waiters(struct seq *seq) OVS_REQUIRES(seq_mutex) { - struct seq_waiter *waiter, *next_waiter; + struct seq_waiter *waiter; - HMAP_FOR_EACH_SAFE (waiter, next_waiter, hmap_node, &seq->waiters) { + HMAP_FOR_EACH_SAFE (waiter, hmap_node, &seq->waiters) { latch_set(&waiter->thread->latch); seq_waiter_destroy(waiter); } diff --git a/lib/shash.c b/lib/shash.c index a8433629a..a7b2c6458 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -68,9 +68,9 @@ shash_moved(struct shash *sh) void shash_clear(struct shash *sh) { - struct shash_node *node, *next; + struct shash_node *node; - SHASH_FOR_EACH_SAFE (node, next, sh) { + SHASH_FOR_EACH_SAFE (node, sh) { hmap_remove(&sh->map, &node->node); free(node->name); free(node); @@ -81,9 +81,9 @@ shash_clear(struct shash *sh) void shash_clear_free_data(struct shash *sh) { - struct shash_node *node, *next; + struct shash_node *node; - SHASH_FOR_EACH_SAFE (node, next, sh) { + SHASH_FOR_EACH_SAFE (node, sh) { hmap_remove(&sh->map, &node->node); free(node->data); free(node->name); diff --git a/lib/simap.c b/lib/simap.c index f404ece67..0ee08d74d 100644 --- a/lib/simap.c +++ b/lib/simap.c @@ -63,9 +63,9 @@ simap_moved(struct simap *simap) void simap_clear(struct simap *simap) { - struct simap_node *node, *next; + struct simap_node *node; - SIMAP_FOR_EACH_SAFE (node, next, simap) { + SIMAP_FOR_EACH_SAFE (node, simap) { hmap_remove(&simap->map, &node->node); free(node->name); free(node); diff --git a/lib/simap.h b/lib/simap.h index 5e646e660..e61854ff9 100644 --- a/lib/simap.h +++ b/lib/simap.h @@ -41,10 +41,9 @@ struct simap_node { BUILD_ASSERT_TYPE(SIMAP_NODE, struct simap_node *), \ BUILD_ASSERT_TYPE(SIMAP, struct simap *)) -#define SIMAP_FOR_EACH_SAFE(SIMAP_NODE, NEXT, SIMAP) \ - HMAP_FOR_EACH_SAFE_INIT (SIMAP_NODE, NEXT, node, &(SIMAP)->map, \ +#define SIMAP_FOR_EACH_SAFE(SIMAP_NODE, SIMAP) \ + HMAP_FOR_EACH_SAFE_INIT (SIMAP_NODE, node, &(SIMAP)->map, \ BUILD_ASSERT_TYPE(SIMAP_NODE, struct simap_node *), \ - BUILD_ASSERT_TYPE(NEXT, struct simap_node *), \ BUILD_ASSERT_TYPE(SIMAP, struct simap *)) void simap_init(struct simap *); diff --git a/lib/smap.c b/lib/smap.c index e82261497..b23eeb52d 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -185,9 +185,9 @@ smap_steal(struct smap *smap, struct smap_node *node, void smap_clear(struct smap *smap) { - struct smap_node *node, *next; + struct smap_node *node; - SMAP_FOR_EACH_SAFE (node, next, smap) { + SMAP_FOR_EACH_SAFE (node, smap) { smap_remove_node(smap, node); } } diff --git a/lib/smap.h b/lib/smap.h index a92115966..029e9c47f 100644 --- a/lib/smap.h +++ b/lib/smap.h @@ -45,11 +45,10 @@ struct smap_node { BUILD_ASSERT_TYPE(SMAP_NODE, struct smap_node *), \ BUILD_ASSERT_TYPE(SMAP, struct smap *)) -#define SMAP_FOR_EACH_SAFE(SMAP_NODE, NEXT, SMAP) \ +#define SMAP_FOR_EACH_SAFE(SMAP_NODE, SMAP) \ HMAP_FOR_EACH_SAFE_INIT ( \ - SMAP_NODE, NEXT, node, &(SMAP)->map, \ + SMAP_NODE, node, &(SMAP)->map, \ BUILD_ASSERT_TYPE(SMAP_NODE, struct smap_node *), \ - BUILD_ASSERT_TYPE(NEXT, struct smap_node *), \ BUILD_ASSERT_TYPE(SMAP, struct smap *)) /* Initializer for an immutable struct smap 'SMAP' that contains one or two diff --git a/lib/stopwatch.c b/lib/stopwatch.c index f5602163b..8e1b1d3f1 100644 --- a/lib/stopwatch.c +++ b/lib/stopwatch.c @@ -466,7 +466,7 @@ stopwatch_thread(void *ign OVS_UNUSED) static void stopwatch_exit(void) { - struct shash_node *node, *node_next; + struct shash_node *node; struct stopwatch_packet *pkt = stopwatch_packet_create(OP_SHUTDOWN); stopwatch_packet_write(pkt); xpthread_join(stopwatch_thread_id, NULL); @@ -475,7 +475,7 @@ stopwatch_exit(void) * other competing thread. We are now the sole owners * of all data in the file. */ - SHASH_FOR_EACH_SAFE (node, node_next, &stopwatches) { + SHASH_FOR_EACH_SAFE (node, &stopwatches) { struct stopwatch *sw = node->data; shash_delete(&stopwatches, node); free(sw); diff --git a/ofproto/bond.c b/ofproto/bond.c index 6e95dfdff..29dbf6e4e 100644 --- a/ofproto/bond.c +++ b/ofproto/bond.c @@ -338,7 +338,7 @@ static void update_recirc_rules__(struct bond *bond) { struct match match; - struct bond_pr_rule_op *pr_op, *next_op; + struct bond_pr_rule_op *pr_op; uint64_t ofpacts_stub[128 / 8]; struct ofpbuf ofpacts; int i; @@ -372,7 +372,7 @@ update_recirc_rules__(struct bond *bond) ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub); - HMAP_FOR_EACH_SAFE(pr_op, next_op, hmap_node, &bond->pr_rule_ops) { + HMAP_FOR_EACH_SAFE(pr_op, hmap_node, &bond->pr_rule_ops) { int error; switch (pr_op->op) { case ADD: diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 5666d7283..172a58cfb 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -310,8 +310,8 @@ connmgr_destroy(struct connmgr *mgr) return; } - struct ofservice *ofservice, *next_ofservice; - HMAP_FOR_EACH_SAFE (ofservice, next_ofservice, hmap_node, &mgr->services) { + struct ofservice *ofservice; + HMAP_FOR_EACH_SAFE (ofservice, hmap_node, &mgr->services) { ofservice_destroy(ofservice); } hmap_destroy(&mgr->services); @@ -592,8 +592,8 @@ connmgr_set_controllers(struct connmgr *mgr, struct shash *controllers) /* Delete services that are no longer configured. * Update configuration of all now-existing services. */ - struct ofservice *ofservice, *next_ofservice; - HMAP_FOR_EACH_SAFE (ofservice, next_ofservice, hmap_node, &mgr->services) { + struct ofservice *ofservice; + HMAP_FOR_EACH_SAFE (ofservice, hmap_node, &mgr->services) { const char *target = ofservice->target; struct ofproto_controller *c = shash_find_data(controllers, target); if (!c) { @@ -1137,9 +1137,9 @@ ofconn_remove_bundle(struct ofconn *ofconn, struct ofp_bundle *bundle) static void bundle_remove_all(struct ofconn *ofconn) { - struct ofp_bundle *b, *next; + struct ofp_bundle *b; - HMAP_FOR_EACH_SAFE (b, next, node, &ofconn->bundles) { + HMAP_FOR_EACH_SAFE (b, node, &ofconn->bundles) { ofp_bundle_remove__(ofconn, b); } } @@ -1149,8 +1149,8 @@ bundle_remove_expired(struct ofconn *ofconn, long long int now) { long long int limit = now - bundle_idle_timeout; - struct ofp_bundle *b, *next; - HMAP_FOR_EACH_SAFE (b, next, node, &ofconn->bundles) { + struct ofp_bundle *b; + HMAP_FOR_EACH_SAFE (b, node, &ofconn->bundles) { if (b->used <= limit) { ofconn_send_error(ofconn, b->msg, OFPERR_OFPBFC_TIMEOUT); ofp_bundle_remove__(ofconn, b); @@ -1247,8 +1247,8 @@ ofconn_destroy(struct ofconn *ofconn) free(ofconn->async_cfg); - struct ofmonitor *monitor, *next_monitor; - HMAP_FOR_EACH_SAFE (monitor, next_monitor, ofconn_node, + struct ofmonitor *monitor; + HMAP_FOR_EACH_SAFE (monitor, ofconn_node, &ofconn->monitors) { ofmonitor_destroy(monitor); } diff --git a/ofproto/in-band.c b/ofproto/in-band.c index 82d8dfa14..3992251f5 100644 --- a/ofproto/in-band.c +++ b/ofproto/in-band.c @@ -377,7 +377,7 @@ in_band_run(struct in_band *ib) uint64_t ofpacts_stub[128 / 8]; struct ofpbuf ofpacts; - struct in_band_rule *rule, *next; + struct in_band_rule *rule; ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub); @@ -391,7 +391,7 @@ in_band_run(struct in_band *ib) update_rules(ib); - HMAP_FOR_EACH_SAFE (rule, next, hmap_node, &ib->rules) { + HMAP_FOR_EACH_SAFE (rule, hmap_node, &ib->rules) { switch (rule->op) { case ADD: ofproto_add_flow(ib->ofproto, &rule->match, rule->priority, diff --git a/ofproto/netflow.c b/ofproto/netflow.c index ed58de17d..aad9f9c77 100644 --- a/ofproto/netflow.c +++ b/ofproto/netflow.c @@ -299,7 +299,7 @@ static void netflow_run__(struct netflow *nf) OVS_REQUIRES(mutex) { long long int now = time_msec(); - struct netflow_flow *nf_flow, *next; + struct netflow_flow *nf_flow; if (nf->packet.size) { collectors_send(nf->collectors, nf->packet.data, nf->packet.size); @@ -312,7 +312,7 @@ netflow_run__(struct netflow *nf) OVS_REQUIRES(mutex) nf->next_timeout = now + 1000; - HMAP_FOR_EACH_SAFE (nf_flow, next, hmap_node, &nf->flows) { + HMAP_FOR_EACH_SAFE (nf_flow, hmap_node, &nf->flows) { if (now > nf_flow->last_expired + nf->active_timeout) { bool idle = nf_flow->used < nf_flow->last_expired; netflow_expire__(nf, nf_flow); @@ -416,8 +416,8 @@ netflow_unref(struct netflow *nf) collectors_destroy(nf->collectors); ofpbuf_uninit(&nf->packet); - struct netflow_flow *nf_flow, *next; - HMAP_FOR_EACH_SAFE (nf_flow, next, hmap_node, &nf->flows) { + struct netflow_flow *nf_flow; + HMAP_FOR_EACH_SAFE (nf_flow, hmap_node, &nf->flows) { hmap_remove(&nf->flows, &nf_flow->hmap_node); free(nf_flow); } diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c index f5ae6c16c..4a146dc8f 100644 --- a/ofproto/ofproto-dpif-ipfix.c +++ b/ofproto/ofproto-dpif-ipfix.c @@ -1078,7 +1078,7 @@ dpif_ipfix_set_options( { int i; struct ofproto_ipfix_flow_exporter_options *options; - struct dpif_ipfix_flow_exporter_map_node *node, *next; + struct dpif_ipfix_flow_exporter_map_node *node; ovs_mutex_lock(&mutex); dpif_ipfix_bridge_exporter_set_options(&di->bridge_exporter, @@ -1103,7 +1103,7 @@ dpif_ipfix_set_options( } /* Remove dropped flow exporters, if any needs to be removed. */ - HMAP_FOR_EACH_SAFE (node, next, node, &di->flow_exporter_map) { + HMAP_FOR_EACH_SAFE (node, node, &di->flow_exporter_map) { /* This is slow but doesn't take any extra memory, and * this table is not supposed to contain many rows anyway. */ options = (struct ofproto_ipfix_flow_exporter_options *) @@ -1215,7 +1215,7 @@ static void dpif_ipfix_clear(struct dpif_ipfix *di) OVS_REQUIRES(mutex) { struct dpif_ipfix_flow_exporter_map_node *exp_node; - struct dpif_ipfix_port *dip, *next; + struct dpif_ipfix_port *dip; dpif_ipfix_bridge_exporter_clear(&di->bridge_exporter); @@ -1224,7 +1224,7 @@ dpif_ipfix_clear(struct dpif_ipfix *di) OVS_REQUIRES(mutex) free(exp_node); } - HMAP_FOR_EACH_SAFE (dip, next, hmap_node, &di->ports) { + HMAP_FOR_EACH_SAFE (dip, hmap_node, &di->ports) { dpif_ipfix_del_port__(di, dip); } } diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c index 864c136b5..545b3a456 100644 --- a/ofproto/ofproto-dpif-sflow.c +++ b/ofproto/ofproto-dpif-sflow.c @@ -590,10 +590,10 @@ void dpif_sflow_unref(struct dpif_sflow *ds) OVS_EXCLUDED(mutex) { if (ds && ovs_refcount_unref_relaxed(&ds->ref_cnt) == 1) { - struct dpif_sflow_port *dsp, *next; + struct dpif_sflow_port *dsp; dpif_sflow_clear(ds); - HMAP_FOR_EACH_SAFE (dsp, next, hmap_node, &ds->ports) { + HMAP_FOR_EACH_SAFE (dsp, hmap_node, &ds->ports) { dpif_sflow_del_port__(ds, dsp); } hmap_destroy(&ds->ports); diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 4fdfde91a..010509a53 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -1222,13 +1222,13 @@ xlate_txn_start(void) static void xlate_xcfg_free(struct xlate_cfg *xcfg) { - struct xbridge *xbridge, *next_xbridge; + struct xbridge *xbridge; if (!xcfg) { return; } - HMAP_FOR_EACH_SAFE (xbridge, next_xbridge, hmap_node, &xcfg->xbridges) { + HMAP_FOR_EACH_SAFE (xbridge, hmap_node, &xcfg->xbridges) { xlate_xbridge_remove(xcfg, xbridge); } @@ -1283,13 +1283,13 @@ static void xlate_xbridge_remove(struct xlate_cfg *xcfg, struct xbridge *xbridge) { struct xbundle *xbundle; - struct xport *xport, *next_xport; + struct xport *xport; if (!xbridge) { return; } - HMAP_FOR_EACH_SAFE (xport, next_xport, ofp_node, &xbridge->xports) { + HMAP_FOR_EACH_SAFE (xport, ofp_node, &xbridge->xports) { xlate_xport_remove(xcfg, xport); } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index d9f82924b..af77e3aa1 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1625,7 +1625,7 @@ static int construct(struct ofproto *ofproto_) { struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); - struct shash_node *node, *next; + struct shash_node *node; int error; /* Tunnel module can get used right after the udpif threads are running. */ @@ -1663,7 +1663,7 @@ construct(struct ofproto *ofproto_) ofproto->ams_seqno = seq_read(ofproto->ams_seq); - SHASH_FOR_EACH_SAFE (node, next, &init_ofp_ports) { + SHASH_FOR_EACH_SAFE (node, &init_ofp_ports) { struct iface_hint *iface_hint = node->data; if (!strcmp(iface_hint->br_name, ofproto->up.name)) { diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 56aeac720..1bc92418f 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1709,7 +1709,7 @@ void ofproto_destroy(struct ofproto *p, bool del) OVS_EXCLUDED(ofproto_mutex) { - struct ofport *ofport, *next_ofport; + struct ofport *ofport; struct ofport_usage *usage; if (!p) { @@ -1717,7 +1717,7 @@ ofproto_destroy(struct ofproto *p, bool del) } ofproto_flush__(p, del); - HMAP_FOR_EACH_SAFE (ofport, next_ofport, hmap_node, &p->ports) { + HMAP_FOR_EACH_SAFE (ofport, hmap_node, &p->ports) { ofport_destroy(ofport, del); } @@ -2782,7 +2782,7 @@ init_ports(struct ofproto *p) { struct ofproto_port_dump dump; struct ofproto_port ofproto_port; - struct shash_node *node, *next; + struct shash_node *node; OFPROTO_PORT_FOR_EACH (&ofproto_port, &dump, p) { const char *name = ofproto_port.name; @@ -2813,7 +2813,7 @@ init_ports(struct ofproto *p) } } - SHASH_FOR_EACH_SAFE(node, next, &init_ofp_ports) { + SHASH_FOR_EACH_SAFE(node, &init_ofp_ports) { struct iface_hint *iface_hint = node->data; if (!strcmp(iface_hint->br_name, p->name)) { @@ -6797,9 +6797,9 @@ static void meter_delete_all(struct ofproto *ofproto) OVS_REQUIRES(ofproto_mutex) { - struct meter *meter, *next; + struct meter *meter; - HMAP_FOR_EACH_SAFE (meter, next, node, &ofproto->meters) { + HMAP_FOR_EACH_SAFE (meter, node, &ofproto->meters) { hmap_remove(&ofproto->meters, &meter->node); meter_destroy(ofproto, meter); } @@ -9138,8 +9138,8 @@ oftable_configure_eviction(struct oftable *table, unsigned int eviction, /* Destroy existing eviction groups, then destroy and recreate data * structures to recover memory. */ - struct eviction_group *evg, *next; - HMAP_FOR_EACH_SAFE (evg, next, id_node, &table->eviction_groups_by_id) { + struct eviction_group *evg; + HMAP_FOR_EACH_SAFE (evg, id_node, &table->eviction_groups_by_id) { eviction_group_destroy(table, evg); } hmap_destroy(&table->eviction_groups_by_id); diff --git a/ovsdb/condition.c b/ovsdb/condition.c index 388dd54a1..17e38a2cf 100644 --- a/ovsdb/condition.c +++ b/ovsdb/condition.c @@ -220,13 +220,13 @@ ovsdb_condition_optimize(struct ovsdb_condition *cnd) static void ovsdb_condition_optimize_destroy(struct ovsdb_condition *cnd) { - struct shash_node *node, *next; + struct shash_node *node; - SHASH_FOR_EACH_SAFE (node, next, &cnd->o_columns) { + SHASH_FOR_EACH_SAFE (node, &cnd->o_columns) { struct ovsdb_o_column *o_column = node->data; - struct ovsdb_o_clause *c, *c_next; + struct ovsdb_o_clause *c; - HMAP_FOR_EACH_SAFE(c, c_next, hmap_node, &o_column->o_clauses) { + HMAP_FOR_EACH_SAFE(c, hmap_node, &o_column->o_clauses) { hmap_remove(&o_column->o_clauses, &c->hmap_node); free(c); } diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index d091602d5..916a1f414 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -197,9 +197,9 @@ ovsdb_jsonrpc_server_remove_db(struct ovsdb_jsonrpc_server *svr, void ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr) { - struct shash_node *node, *next; + struct shash_node *node; - SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) { + SHASH_FOR_EACH_SAFE (node, &svr->remotes) { ovsdb_jsonrpc_server_del_remote(node); } shash_destroy(&svr->remotes); @@ -227,9 +227,9 @@ void ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr, const struct shash *new_remotes) { - struct shash_node *node, *next; + struct shash_node *node; - SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) { + SHASH_FOR_EACH_SAFE (node, &svr->remotes) { struct ovsdb_jsonrpc_remote *remote = node->data; struct ovsdb_jsonrpc_options *options = shash_find_data(new_remotes, node->name); @@ -909,9 +909,9 @@ error: static void ovsdb_jsonrpc_session_unlock_all(struct ovsdb_jsonrpc_session *s) { - struct ovsdb_lock_waiter *waiter, *next; + struct ovsdb_lock_waiter *waiter; - HMAP_FOR_EACH_SAFE (waiter, next, session_node, &s->up.waiters) { + HMAP_FOR_EACH_SAFE (waiter, session_node, &s->up.waiters) { ovsdb_jsonrpc_session_unlock__(waiter); } } @@ -1198,8 +1198,8 @@ static void ovsdb_jsonrpc_trigger_remove__(struct ovsdb_jsonrpc_session *s, struct ovsdb *db) { - struct ovsdb_jsonrpc_trigger *t, *next; - HMAP_FOR_EACH_SAFE (t, next, hmap_node, &s->triggers) { + struct ovsdb_jsonrpc_trigger *t; + HMAP_FOR_EACH_SAFE (t, hmap_node, &s->triggers) { if (!db || t->trigger.db == db) { ovsdb_jsonrpc_trigger_complete(t); } @@ -1688,8 +1688,8 @@ ovsdb_jsonrpc_monitor_preremove_db(struct ovsdb_jsonrpc_session *s, { ovs_assert(db); - struct ovsdb_jsonrpc_monitor *m, *next; - HMAP_FOR_EACH_SAFE (m, next, node, &s->monitors) { + struct ovsdb_jsonrpc_monitor *m; + HMAP_FOR_EACH_SAFE (m, node, &s->monitors) { if (m->db == db) { ovsdb_jsonrpc_monitor_destroy(m, true); } @@ -1700,9 +1700,9 @@ ovsdb_jsonrpc_monitor_preremove_db(struct ovsdb_jsonrpc_session *s, static void ovsdb_jsonrpc_monitor_remove_all(struct ovsdb_jsonrpc_session *s) { - struct ovsdb_jsonrpc_monitor *m, *next; + struct ovsdb_jsonrpc_monitor *m; - HMAP_FOR_EACH_SAFE (m, next, node, &s->monitors) { + HMAP_FOR_EACH_SAFE (m, node, &s->monitors) { ovsdb_jsonrpc_monitor_destroy(m, false); } } diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index 11777ecf7..97dd0858f 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -640,8 +640,8 @@ ovsdb_monitor_change_set_destroy(struct ovsdb_monitor_change_set *mcs) ovs_list_remove(&mcst->list_in_change_set); ovs_list_remove(&mcst->list_in_mt); - struct ovsdb_monitor_row *row, *next; - HMAP_FOR_EACH_SAFE (row, next, hmap_node, &mcst->rows) { + struct ovsdb_monitor_row *row; + HMAP_FOR_EACH_SAFE (row, hmap_node, &mcst->rows) { hmap_remove(&mcst->rows, &row->hmap_node); ovsdb_monitor_row_destroy(mcst->mt, row, mcst->n_columns); } @@ -696,13 +696,13 @@ void ovsdb_monitor_session_condition_destroy( struct ovsdb_monitor_session_condition *condition) { - struct shash_node *node, *next; + struct shash_node *node; if (!condition) { return; } - SHASH_FOR_EACH_SAFE (node, next, &condition->tables) { + SHASH_FOR_EACH_SAFE (node, &condition->tables) { struct ovsdb_monitor_table_condition *mtc = node->data; ovsdb_condition_destroy(&mtc->new_condition); @@ -1118,11 +1118,11 @@ ovsdb_monitor_compose_update( json = NULL; struct ovsdb_monitor_change_set_for_table *mcst; LIST_FOR_EACH (mcst, list_in_change_set, &mcs->change_set_for_tables) { - struct ovsdb_monitor_row *row, *next; + struct ovsdb_monitor_row *row; struct json *table_json = NULL; struct ovsdb_monitor_table *mt = mcst->mt; - HMAP_FOR_EACH_SAFE (row, next, hmap_node, &mcst->rows) { + HMAP_FOR_EACH_SAFE (row, hmap_node, &mcst->rows) { struct json *row_json; row_json = (*row_update)(mt, condition, OVSDB_MONITOR_ROW, row, initial, changed, mcst->n_columns); diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 9fe90592e..6e2dd1ab8 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -228,8 +228,7 @@ main_loop(struct server_config *config, ovsdb_relay_run(); - struct shash_node *next; - SHASH_FOR_EACH_SAFE (node, next, all_dbs) { + SHASH_FOR_EACH_SAFE (node, all_dbs) { struct db *db = node->data; ovsdb_txn_history_run(db->db); ovsdb_storage_run(db->db->storage); @@ -321,7 +320,7 @@ main(int argc, char *argv[]) FILE *config_tmpfile; struct server_config server_config; struct shash all_dbs; - struct shash_node *node, *next; + struct shash_node *node; int replication_probe_interval = REPLICATION_DEFAULT_PROBE_INTERVAL; ovs_cmdl_proctitle_init(argc, argv); @@ -490,7 +489,7 @@ main(int argc, char *argv[]) main_loop(&server_config, jsonrpc, &all_dbs, unixctl, &remotes, run_process, &exiting, &is_backup); - SHASH_FOR_EACH_SAFE(node, next, &all_dbs) { + SHASH_FOR_EACH_SAFE(node, &all_dbs) { struct db *db = node->data; close_db(&server_config, db, NULL); shash_delete(&all_dbs, node); @@ -1240,8 +1239,8 @@ update_server_status(struct shash *all_dbs) /* Update rows for databases that still exist. * Delete rows for databases that no longer exist. */ - const struct ovsdb_row *row, *next_row; - HMAP_FOR_EACH_SAFE (row, next_row, hmap_node, &database_table->rows) { + const struct ovsdb_row *row; + HMAP_FOR_EACH_SAFE (row, hmap_node, &database_table->rows) { const char *name; ovsdb_util_read_string_column(row, "name", &name); struct db *db = shash_find_data(all_dbs, name); diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c index d4a9e34cc..df2e373c3 100644 --- a/ovsdb/ovsdb-tool.c +++ b/ovsdb/ovsdb-tool.c @@ -1579,15 +1579,14 @@ do_check_cluster(struct ovs_cmdl_context *ctx) } free(c.servers); - struct commit *next_commit; - HMAP_FOR_EACH_SAFE (commit, next_commit, hmap_node, &c.commits) { + HMAP_FOR_EACH_SAFE (commit, hmap_node, &c.commits) { hmap_remove(&c.commits, &commit->hmap_node); free(commit); } hmap_destroy(&c.commits); - struct leader *leader, *next_leader; - HMAP_FOR_EACH_SAFE (leader, next_leader, hmap_node, &c.leaders) { + struct leader *leader; + HMAP_FOR_EACH_SAFE (leader, hmap_node, &c.leaders) { hmap_remove(&c.leaders, &leader->hmap_node); free(leader); } diff --git a/ovsdb/query.c b/ovsdb/query.c index de7451998..eebe56412 100644 --- a/ovsdb/query.c +++ b/ovsdb/query.c @@ -40,9 +40,9 @@ ovsdb_query(struct ovsdb_table *table, const struct ovsdb_condition *cnd, } } else { /* Linear scan. */ - const struct ovsdb_row *row, *next; + const struct ovsdb_row *row; - HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) { + HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) { if (ovsdb_condition_match_every_clause(row, cnd) && !output_row(row, aux)) { break; diff --git a/ovsdb/raft-private.c b/ovsdb/raft-private.c index 30760233e..f0265848a 100644 --- a/ovsdb/raft-private.c +++ b/ovsdb/raft-private.c @@ -147,8 +147,8 @@ raft_server_destroy(struct raft_server *s) void raft_servers_destroy(struct hmap *servers) { - struct raft_server *s, *next; - HMAP_FOR_EACH_SAFE (s, next, hmap_node, servers) { + struct raft_server *s; + HMAP_FOR_EACH_SAFE (s, hmap_node, servers) { hmap_remove(servers, &s->hmap_node); raft_server_destroy(s); } diff --git a/ovsdb/raft.c b/ovsdb/raft.c index 6666df0d7..aa9abc85a 100644 --- a/ovsdb/raft.c +++ b/ovsdb/raft.c @@ -692,8 +692,8 @@ static void raft_set_servers(struct raft *raft, const struct hmap *new_servers, enum vlog_level level) { - struct raft_server *s, *next; - HMAP_FOR_EACH_SAFE (s, next, hmap_node, &raft->servers) { + struct raft_server *s; + HMAP_FOR_EACH_SAFE (s, hmap_node, &raft->servers) { if (!raft_server_find(new_servers, &s->sid)) { ovs_assert(s != raft->remove_server); @@ -703,7 +703,7 @@ raft_set_servers(struct raft *raft, const struct hmap *new_servers, } } - HMAP_FOR_EACH_SAFE (s, next, hmap_node, new_servers) { + HMAP_FOR_EACH_SAFE (s, hmap_node, new_servers) { if (!raft_find_server(raft, &s->sid)) { VLOG(level, "server %s added to configuration", s->nickname); @@ -2038,8 +2038,8 @@ raft_run(struct raft *raft) * commands becomes new leader: the pending commands can still complete * if the crashed leader has replicated the transactions to majority of * followers before it crashed. */ - struct raft_command *cmd, *next_cmd; - HMAP_FOR_EACH_SAFE (cmd, next_cmd, hmap_node, &raft->commands) { + struct raft_command *cmd; + HMAP_FOR_EACH_SAFE (cmd, hmap_node, &raft->commands) { if (cmd->timestamp && now - cmd->timestamp > raft->election_timer * 2) { raft_command_complete(raft, cmd, RAFT_CMD_TIMEOUT); @@ -2242,8 +2242,8 @@ raft_command_initiate(struct raft *raft, static void log_all_commands(struct raft *raft) { - struct raft_command *cmd, *next; - HMAP_FOR_EACH_SAFE (cmd, next, hmap_node, &raft->commands) { + struct raft_command *cmd; + HMAP_FOR_EACH_SAFE (cmd, hmap_node, &raft->commands) { VLOG_DBG("raft command eid: "UUID_FMT, UUID_ARGS(&cmd->eid)); } } @@ -2397,8 +2397,8 @@ raft_command_complete(struct raft *raft, static void raft_complete_all_commands(struct raft *raft, enum raft_command_status status) { - struct raft_command *cmd, *next; - HMAP_FOR_EACH_SAFE (cmd, next, hmap_node, &raft->commands) { + struct raft_command *cmd; + HMAP_FOR_EACH_SAFE (cmd, hmap_node, &raft->commands) { raft_command_complete(raft, cmd, status); } } diff --git a/ovsdb/relay.c b/ovsdb/relay.c index ef0e44d34..122ee8c52 100644 --- a/ovsdb/relay.c +++ b/ovsdb/relay.c @@ -269,9 +269,9 @@ ovsdb_relay_clear(struct ovsdb *db) SHASH_FOR_EACH (table_node, &db->tables) { struct ovsdb_table *table = table_node->data; - struct ovsdb_row *row, *next; + struct ovsdb_row *row; - HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) { + HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) { ovsdb_txn_row_delete(txn, row); } } diff --git a/ovsdb/replication.c b/ovsdb/replication.c index d8b56d813..477c69d70 100644 --- a/ovsdb/replication.c +++ b/ovsdb/replication.c @@ -549,8 +549,8 @@ reset_database(struct ovsdb *db) /* Delete all rows if the table is not excluded. */ if (!excluded_tables_find(db->schema->name, table_node->name)) { struct ovsdb_table *table = table_node->data; - struct ovsdb_row *row, *next; - HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) { + struct ovsdb_row *row; + HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) { ovsdb_txn_row_delete(txn, row); } } @@ -769,9 +769,9 @@ replication_dbs_destroy(void) return; } - struct shash_node *node, *next; + struct shash_node *node; - SHASH_FOR_EACH_SAFE (node, next, replication_dbs) { + SHASH_FOR_EACH_SAFE (node, replication_dbs) { hmap_remove(&replication_dbs->map, &node->node); struct replication_db *rdb = node->data; if (rdb->active_db_schema) { diff --git a/ovsdb/table.c b/ovsdb/table.c index 455a3663f..2184701ec 100644 --- a/ovsdb/table.c +++ b/ovsdb/table.c @@ -309,10 +309,10 @@ void ovsdb_table_destroy(struct ovsdb_table *table) { if (table) { - struct ovsdb_row *row, *next; + struct ovsdb_row *row; size_t i; - HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) { + HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) { ovsdb_row_destroy(row); } hmap_destroy(&table->rows); diff --git a/ovsdb/transaction-forward.c b/ovsdb/transaction-forward.c index 4549e3427..963e93795 100644 --- a/ovsdb/transaction-forward.c +++ b/ovsdb/transaction-forward.c @@ -167,9 +167,9 @@ ovsdb_txn_forward_cancel(struct ovsdb *db, struct ovsdb_txn_forward *txn_fwd) void ovsdb_txn_forward_cancel_all(struct ovsdb *db, bool sent_only) { - struct ovsdb_txn_forward *t, *next; + struct ovsdb_txn_forward *t; - HMAP_FOR_EACH_SAFE (t, next, sent_node, &db->txn_forward_sent) { + HMAP_FOR_EACH_SAFE (t, sent_node, &db->txn_forward_sent) { ovsdb_txn_forward_cancel(db, t); } diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index a51c365ab..ce6685e9a 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -1096,8 +1096,8 @@ ovsdb_txn_destroy_cloned(struct ovsdb_txn *txn) ovs_assert(!txn->db); struct ovsdb_txn_table *t; LIST_FOR_EACH_SAFE (t, node, &txn->txn_tables) { - struct ovsdb_txn_row *r, *next_txn_row; - HMAP_FOR_EACH_SAFE (r, next_txn_row, hmap_node, &t->txn_rows) { + struct ovsdb_txn_row *r; + HMAP_FOR_EACH_SAFE (r, hmap_node, &t->txn_rows) { if (r->old) { ovsdb_row_destroy(r->old); } @@ -1559,9 +1559,9 @@ for_each_txn_row(struct ovsdb_txn *txn, } while (t->n_processed < hmap_count(&t->txn_rows)) { - struct ovsdb_txn_row *r, *next_txn_row; + struct ovsdb_txn_row *r; - HMAP_FOR_EACH_SAFE (r, next_txn_row, hmap_node, &t->txn_rows) { + HMAP_FOR_EACH_SAFE (r, hmap_node, &t->txn_rows) { if (r->serial != serial) { struct ovsdb_error *error; diff --git a/tests/test-cmap.c b/tests/test-cmap.c index 070547560..bc1f45642 100644 --- a/tests/test-cmap.c +++ b/tests/test-cmap.c @@ -584,7 +584,7 @@ benchmark_hmap(void) { struct helement *elements; struct hmap hmap; - struct helement *e, *next; + struct helement *e; struct timeval start; pthread_t *threads; struct hmap_aux aux; @@ -622,7 +622,7 @@ benchmark_hmap(void) /* Destruction. */ xgettimeofday(&start); - HMAP_FOR_EACH_SAFE (e, next, node, &hmap) { + HMAP_FOR_EACH_SAFE (e, node, &hmap) { hmap_remove(&hmap, &e->node); } hmap_destroy(&hmap); diff --git a/tests/test-hmap.c b/tests/test-hmap.c index 9259b0b3f..bbadf6660 100644 --- a/tests/test-hmap.c +++ b/tests/test-hmap.c @@ -234,7 +234,7 @@ test_hmap_for_each_safe(hash_func *hash) struct element elements[MAX_ELEMS]; int values[MAX_ELEMS]; struct hmap hmap; - struct element *e, *next; + struct element *e; size_t n_remaining; int i; @@ -242,7 +242,7 @@ test_hmap_for_each_safe(hash_func *hash) i = 0; n_remaining = n; - HMAP_FOR_EACH_SAFE (e, next, node, &hmap) { + HMAP_FOR_EACH_SAFE (e, node, &hmap) { assert(i < n); if (pattern & (1ul << e->value)) { size_t j; diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 812455eea..14f5cb92e 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1525,11 +1525,11 @@ del_port(struct vsctl_context *vsctl_ctx, struct vsctl_port *port) static void del_bridge(struct vsctl_context *vsctl_ctx, struct vsctl_bridge *br) { - struct vsctl_bridge *child, *next_child; + struct vsctl_bridge *child; struct vsctl_port *port; const struct ovsrec_flow_sample_collector_set *fscset, *next_fscset; - HMAP_FOR_EACH_SAFE (child, next_child, children_node, &br->children) { + HMAP_FOR_EACH_SAFE (child, children_node, &br->children) { del_bridge(vsctl_ctx, child); } diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index b1bc51bd5..e328d8ead 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -543,13 +543,13 @@ bridge_exit(bool delete_datapath) if_notifier_destroy(ifnotifier); seq_destroy(ifaces_changed); - struct datapath *dp, *next; - HMAP_FOR_EACH_SAFE (dp, next, node, &all_datapaths) { + struct datapath *dp; + HMAP_FOR_EACH_SAFE (dp, node, &all_datapaths) { datapath_destroy(dp); } - struct bridge *br, *next_br; - HMAP_FOR_EACH_SAFE (br, next_br, node, &all_bridges) { + struct bridge *br; + HMAP_FOR_EACH_SAFE (br, node, &all_bridges) { bridge_destroy(br, delete_datapath); } @@ -716,8 +716,8 @@ static void datapath_destroy(struct datapath *dp) { if (dp) { - struct ct_zone *ct_zone, *next; - HMAP_FOR_EACH_SAFE (ct_zone, next, node, &dp->ct_zones) { + struct ct_zone *ct_zone; + HMAP_FOR_EACH_SAFE (ct_zone, node, &dp->ct_zones) { ofproto_ct_del_zone_timeout_policy(dp->type, ct_zone->zone_id); ct_zone_remove_and_destroy(dp, ct_zone); } @@ -733,7 +733,7 @@ datapath_destroy(struct datapath *dp) static void ct_zones_reconfigure(struct datapath *dp, struct ovsrec_datapath *dp_cfg) { - struct ct_zone *ct_zone, *next; + struct ct_zone *ct_zone; /* Add new 'ct_zone's or update existing 'ct_zone's based on the database * state. */ @@ -760,7 +760,7 @@ ct_zones_reconfigure(struct datapath *dp, struct ovsrec_datapath *dp_cfg) } /* Purge 'ct_zone's no longer found in the database. */ - HMAP_FOR_EACH_SAFE (ct_zone, next, node, &dp->ct_zones) { + HMAP_FOR_EACH_SAFE (ct_zone, node, &dp->ct_zones) { if (ct_zone->last_used != idl_seqno) { ofproto_ct_del_zone_timeout_policy(dp->type, ct_zone->zone_id); ct_zone_remove_and_destroy(dp, ct_zone); @@ -788,7 +788,7 @@ dp_capability_reconfigure(struct datapath *dp, static void datapath_reconfigure(const struct ovsrec_open_vswitch *cfg) { - struct datapath *dp, *next; + struct datapath *dp; /* Add new 'datapath's or update existing ones. */ for (size_t i = 0; i < cfg->n_datapaths; i++) { @@ -805,7 +805,7 @@ datapath_reconfigure(const struct ovsrec_open_vswitch *cfg) } /* Purge deleted 'datapath's. */ - HMAP_FOR_EACH_SAFE (dp, next, node, &all_datapaths) { + HMAP_FOR_EACH_SAFE (dp, node, &all_datapaths) { if (dp->last_used != idl_seqno) { datapath_destroy(dp); } @@ -816,7 +816,7 @@ static void bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) { struct sockaddr_in *managers; - struct bridge *br, *next; + struct bridge *br; int sflow_bridge_number; size_t n_managers; @@ -875,7 +875,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) * - Create ofprotos that are missing. * * - Add ports that are missing. */ - HMAP_FOR_EACH_SAFE (br, next, node, &all_bridges) { + HMAP_FOR_EACH_SAFE (br, node, &all_bridges) { if (!br->ofproto) { int error; @@ -1020,7 +1020,7 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) struct ofproto_port_dump dump; struct sset ofproto_ports; - struct port *port, *port_next; + struct port *port; /* List of "ofp_port"s to delete. We make a list instead of deleting them * right away because ofproto implementations aren't necessarily able to @@ -1132,7 +1132,7 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) * device destroyed via "tunctl -d", a physical Ethernet device * whose module was just unloaded via "rmmod", or a virtual NIC for a * VM whose VM was just terminated. */ - HMAP_FOR_EACH_SAFE (port, port_next, hmap_node, &br->ports) { + HMAP_FOR_EACH_SAFE (port, hmap_node, &br->ports) { struct iface *iface; LIST_FOR_EACH_SAFE (iface, port_elem, &port->ifaces) { @@ -1967,7 +1967,7 @@ port_is_bond_fake_iface(const struct port *port) static void add_del_bridges(const struct ovsrec_open_vswitch *cfg) { - struct bridge *br, *next; + struct bridge *br; struct shash_node *node; struct shash new_br; size_t i; @@ -1993,7 +1993,7 @@ add_del_bridges(const struct ovsrec_open_vswitch *cfg) /* Get rid of deleted bridges or those whose types have changed. * Update 'cfg' of bridges that still exist. */ - HMAP_FOR_EACH_SAFE (br, next, node, &all_bridges) { + HMAP_FOR_EACH_SAFE (br, node, &all_bridges) { br->cfg = shash_find_data(&new_br, br->name); if (!br->cfg || strcmp(br->type, ofproto_normalize_type( br->cfg->datapath_type))) { @@ -3266,13 +3266,13 @@ bridge_run(void) if (ovsdb_idl_is_lock_contended(idl)) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); - struct bridge *br, *next_br; + struct bridge *br; VLOG_ERR_RL(&rl, "another ovs-vswitchd process is running, " "disabling this process (pid %ld) until it goes away", (long int) getpid()); - HMAP_FOR_EACH_SAFE (br, next_br, node, &all_bridges) { + HMAP_FOR_EACH_SAFE (br, node, &all_bridges) { bridge_destroy(br, false); } /* Since we will not be running system_stats_run() in this process @@ -3594,13 +3594,13 @@ static void bridge_destroy(struct bridge *br, bool del) { if (br) { - struct mirror *mirror, *next_mirror; - struct port *port, *next_port; + struct mirror *mirror; + struct port *port; - HMAP_FOR_EACH_SAFE (port, next_port, hmap_node, &br->ports) { + HMAP_FOR_EACH_SAFE (port, hmap_node, &br->ports) { port_destroy(port); } - HMAP_FOR_EACH_SAFE (mirror, next_mirror, hmap_node, &br->mirrors) { + HMAP_FOR_EACH_SAFE (mirror, hmap_node, &br->mirrors) { mirror_destroy(mirror); } @@ -3746,11 +3746,11 @@ static void bridge_del_ports(struct bridge *br, const struct shash *wanted_ports) { struct shash_node *port_node; - struct port *port, *next; + struct port *port; /* Get rid of deleted ports. * Get rid of deleted interfaces on ports that still exist. */ - HMAP_FOR_EACH_SAFE (port, next, hmap_node, &br->ports) { + HMAP_FOR_EACH_SAFE (port, hmap_node, &br->ports) { port->cfg = shash_find_data(wanted_ports, port->name); if (!port->cfg) { port_destroy(port); @@ -4211,7 +4211,7 @@ bridge_configure_aa(struct bridge *br) const struct ovsdb_datum *mc; struct ovsrec_autoattach *auto_attach = br->cfg->auto_attach; struct aa_settings aa_s; - struct aa_mapping *m, *next; + struct aa_mapping *m; size_t i; if (!auto_attach) { @@ -4227,7 +4227,7 @@ bridge_configure_aa(struct bridge *br) mc = ovsrec_autoattach_get_mappings(auto_attach, OVSDB_TYPE_INTEGER, OVSDB_TYPE_INTEGER); - HMAP_FOR_EACH_SAFE (m, next, hmap_node, &br->mappings) { + HMAP_FOR_EACH_SAFE (m, hmap_node, &br->mappings) { union ovsdb_atom atom; atom.integer = m->isid; @@ -5013,12 +5013,12 @@ bridge_configure_mirrors(struct bridge *br) { const struct ovsdb_datum *mc; unsigned long *flood_vlans; - struct mirror *m, *next; + struct mirror *m; size_t i; /* Get rid of deleted mirrors. */ mc = ovsrec_bridge_get_mirrors(br->cfg, OVSDB_TYPE_UUID); - HMAP_FOR_EACH_SAFE (m, next, hmap_node, &br->mirrors) { + HMAP_FOR_EACH_SAFE (m, hmap_node, &br->mirrors) { union ovsdb_atom atom; atom.uuid = m->uuid; diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c index 3465d899b..99c4adcd5 100644 --- a/vtep/vtep-ctl.c +++ b/vtep/vtep-ctl.c @@ -801,12 +801,12 @@ vtep_ctl_context_invalidate_cache(struct ctl_context *ctx) SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) { struct vtep_ctl_lswitch *ls = node->data; - struct shash_node *node2, *next_node2; + struct shash_node *node2; shash_destroy(&ls->ucast_local); shash_destroy(&ls->ucast_remote); - SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_local) { + SHASH_FOR_EACH_SAFE (node2, &ls->mcast_local) { struct vtep_ctl_mcast_mac *mcast_mac = node2->data; struct vtep_ctl_ploc *ploc; @@ -818,7 +818,7 @@ vtep_ctl_context_invalidate_cache(struct ctl_context *ctx) } shash_destroy(&ls->mcast_local); - SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_remote) { + SHASH_FOR_EACH_SAFE (node2, &ls->mcast_remote) { struct vtep_ctl_mcast_mac *mcast_mac = node2->data; struct vtep_ctl_ploc *ploc; From patchwork Mon Jan 24 10:34:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583384 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=En5158a9; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5xb1brYz9t0k for ; Mon, 24 Jan 2022 21:36:19 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id A677C60ED2; Mon, 24 Jan 2022 10:36:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ztTCHWmTaBGw; Mon, 24 Jan 2022 10:36:14 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id BAA9260E4E; Mon, 24 Jan 2022 10:36:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 04D17C007A; Mon, 24 Jan 2022 10:36:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 52661C007A for ; Mon, 24 Jan 2022 10:36:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 7A7A560E8A for ; Mon, 24 Jan 2022 10:35:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vd6Q-F-iDB5b for ; Mon, 24 Jan 2022 10:35:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id C438160E87 for ; Mon, 24 Jan 2022 10:35:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FusWT1symbLCrfHqX8JYstduLDreMImZEYFN6j3p8KU=; b=En5158a9EgeJpgKZPGQDg7LZVjRz/PX6LXPxDDIYUqQmaAMnljiururXBbxtEKDAZwFVkd HKRnppMbi33kuibH/fI6l0HLhDgAcol36oxE3iO+OCehvze7jOASAELjM5q4FWwmGrD+Gq IIJB2loMzgnhskWXC4ORT4SBD+Gxuhs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-212-gMR_o31IN1699dxtuv-lSw-1; Mon, 24 Jan 2022 05:35:31 -0500 X-MC-Unique: gMR_o31IN1699dxtuv-lSw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9769B1006AA4; Mon, 24 Jan 2022 10:35:30 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C79D7A235; Mon, 24 Jan 2022 10:35:28 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:41 +0100 Message-Id: <20220124103445.2459400-10-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 09/13] cmap: use multi-variable iterators X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Re-write cmap's loops using multi-variable helpers. For iterators based on cmap_cursor, we just need to make sure the NODE variable is not used after the loop, so we set it to NULL. Signed-off-by: Adrian Moreno --- lib/cmap.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/cmap.h b/lib/cmap.h index c502d2311..26f4f6644 100644 --- a/lib/cmap.h +++ b/lib/cmap.h @@ -108,6 +108,8 @@ size_t cmap_replace(struct cmap *, struct cmap_node *old_node, * * CMAP and HASH are evaluated only once. NODE is evaluated many times. * + * After a normal exit of the loop (not through a "break;" statement) NODE is + * NULL. * * Thread-safety * ============= @@ -128,15 +130,17 @@ size_t cmap_replace(struct cmap *, struct cmap_node *old_node, * CMAP_FOR_EACH_WITH_HASH_PROTECTED may only be used if CMAP is guaranteed not * to change during iteration. It may be very slightly faster. */ -#define CMAP_NODE_FOR_EACH(NODE, MEMBER, CMAP_NODE) \ - for (INIT_CONTAINER(NODE, CMAP_NODE, MEMBER); \ - (NODE) != OBJECT_CONTAINING(NULL, NODE, MEMBER); \ - ASSIGN_CONTAINER(NODE, cmap_node_next(&(NODE)->MEMBER), MEMBER)) -#define CMAP_NODE_FOR_EACH_PROTECTED(NODE, MEMBER, CMAP_NODE) \ - for (INIT_CONTAINER(NODE, CMAP_NODE, MEMBER); \ - (NODE) != OBJECT_CONTAINING(NULL, NODE, MEMBER); \ - ASSIGN_CONTAINER(NODE, cmap_node_next_protected(&(NODE)->MEMBER), \ - MEMBER)) +#define CMAP_NODE_FOR_EACH(NODE, MEMBER, CMAP_NODE) \ + for (INIT_MULTIVAR(NODE, MEMBER, CMAP_NODE); \ + CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(NODE) = cmap_node_next(ITER_VAR(NODE)), \ + NODE)) +#define CMAP_NODE_FOR_EACH_PROTECTED(NODE, MEMBER, CMAP_NODE) \ + for (INIT_MULTIVAR(NODE, MEMBER, CMAP_NODE); \ + CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER); \ + UPDATE_MULTIVAR( \ + ITER_VAR(NODE) = cmap_node_next_protected(ITER_VAR(NODE)), \ + NODE)) #define CMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, CMAP) \ CMAP_NODE_FOR_EACH(NODE, MEMBER, cmap_find(CMAP, HASH)) #define CMAP_FOR_EACH_WITH_HASH_PROTECTED(NODE, MEMBER, HASH, CMAP) \ @@ -223,7 +227,7 @@ unsigned long cmap_find_batch(const struct cmap *cmap, unsigned long map, ? (INIT_CONTAINER(NODE, (CURSOR)->node, MEMBER), \ cmap_cursor_advance(CURSOR), \ true) \ - : false) + : (NODE = NULL, false)) #define CMAP_CURSOR_FOR_EACH(NODE, MEMBER, CURSOR, CMAP) \ for (*(CURSOR) = cmap_cursor_start(CMAP); \ From patchwork Mon Jan 24 10:34:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Rl1HaXo/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5xW2vC9z9t0k for ; Mon, 24 Jan 2022 21:36:15 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 13C6860F09; Mon, 24 Jan 2022 10:36:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lMBn43Dx15-7; Mon, 24 Jan 2022 10:36:12 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 3ADB660E7E; Mon, 24 Jan 2022 10:36:11 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0F3F0C0039; Mon, 24 Jan 2022 10:36:11 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6B353C002F for ; Mon, 24 Jan 2022 10:36:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 03187410B2 for ; Mon, 24 Jan 2022 10:35:42 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wqovmj56oOf0 for ; Mon, 24 Jan 2022 10:35:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id 1553741295 for ; Mon, 24 Jan 2022 10:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wb5OBPDLu8pqvPKSyBA/rqhIjimHcERepFFaGGNFR1g=; b=Rl1HaXo/P+cv6rrAO5YVP3vPuprctdK3nBsmJHQiuZrux7/S4nUvtyA2h0v5gX+/G14JkR VSjGoTj8lPeZ39BF26+RF1dbZYBrkdui/X4bHEYW8o3sZsuQBuvnNunUhELJuMKVn9G94+ xLLc9D2hv4OthtR6rY85eRb3CHjOAYI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-Zkz0IE-4Pbii-2qXq4Yiww-1; Mon, 24 Jan 2022 05:35:33 -0500 X-MC-Unique: Zkz0IE-4Pbii-2qXq4Yiww-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB6208143EA; Mon, 24 Jan 2022 10:35:32 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB75C7A235; Mon, 24 Jan 2022 10:35:30 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:42 +0100 Message-Id: <20220124103445.2459400-11-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 10/13] hindex: use multi-variable iterators X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Re-write hindex's loops using multi-variable helpers. For safe loops, keep the (now unused) NEXT variable to maintain backwards compatibility. Signed-off-by: Adrian Moreno --- lib/hindex.h | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/hindex.h b/lib/hindex.h index 876c5a9e3..7b122744a 100644 --- a/lib/hindex.h +++ b/lib/hindex.h @@ -128,18 +128,20 @@ void hindex_remove(struct hindex *, struct hindex_node *); * Evaluates HASH only once. */ #define HINDEX_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HINDEX) \ - for (INIT_CONTAINER(NODE, hindex_node_with_hash(HINDEX, HASH), MEMBER); \ - NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER); \ - ASSIGN_CONTAINER(NODE, (NODE)->MEMBER.s, MEMBER)) + for (INIT_MULTIVAR(NODE, MEMBER, hindex_node_with_hash(HINDEX, HASH)); \ + CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(NODE) = ITER_VAR(NODE)->s, NODE)) /* Safe when NODE may be freed (not needed when NODE may be removed from the * hash map but its members remain accessible and intact). */ -#define HINDEX_FOR_EACH_WITH_HASH_SAFE(NODE, NEXT, MEMBER, HASH, HINDEX) \ - for (INIT_CONTAINER(NODE, hindex_node_with_hash(HINDEX, HASH), MEMBER); \ - (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER) \ - ? INIT_CONTAINER(NEXT, (NODE)->MEMBER.s, MEMBER), 1 \ - : 0); \ - (NODE) = (NEXT)) +#define HINDEX_FOR_EACH_WITH_HASH_SAFE(NODE, NEXT, MEMBER, HASH, HINDEX) \ + for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, \ + hindex_node_with_hash(HINDEX, HASH), \ + (void) NEXT); \ + CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL, \ + ITER_NEXT_VAR(NODE) = ITER_VAR(NODE)->s, \ + NODE, MEMBER); \ + UPDATE_MULTIVAR_SAFE(NODE)) /* Returns the head node in 'hindex' with the given 'hash', or a null pointer * if no nodes have that hash value. */ @@ -157,19 +159,21 @@ hindex_node_with_hash(const struct hindex *hindex, size_t hash) /* Iteration. */ /* Iterates through every node in HINDEX. */ -#define HINDEX_FOR_EACH(NODE, MEMBER, HINDEX) \ - for (INIT_CONTAINER(NODE, hindex_first(HINDEX), MEMBER); \ - NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER); \ - ASSIGN_CONTAINER(NODE, hindex_next(HINDEX, &(NODE)->MEMBER), MEMBER)) +#define HINDEX_FOR_EACH(NODE, MEMBER, HINDEX) \ + for (INIT_MULTIVAR(NODE, MEMBER, hindex_first(HINDEX)); \ + CONDITION_MULTIVAR(ITER_VAR(NODE) != NULL, NODE, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(NODE) = hindex_next(HINDEX, ITER_VAR(NODE)),\ + NODE)) /* Safe when NODE may be freed (not needed when NODE may be removed from the * hash index but its members remain accessible and intact). */ -#define HINDEX_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HINDEX) \ - for (INIT_CONTAINER(NODE, hindex_first(HINDEX), MEMBER); \ - (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER) \ - ? INIT_CONTAINER(NEXT, hindex_next(HINDEX, &(NODE)->MEMBER), MEMBER), 1 \ - : 0); \ - (NODE) = (NEXT)) +#define HINDEX_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HINDEX) \ + for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, hindex_first(HINDEX), \ + (void) NEXT); \ + CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL, \ + ITER_NEXT_VAR(NODE) = hindex_next(HINDEX, ITER_VAR(NODE)), \ + NODE, MEMBER); \ + UPDATE_MULTIVAR_SAFE(NODE)) struct hindex_node *hindex_first(const struct hindex *); struct hindex_node *hindex_next(const struct hindex *, From patchwork Mon Jan 24 10:34:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FYNn3FFG; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5xp0mS0z9t0k for ; Mon, 24 Jan 2022 21:36:30 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 3C3C884BB0; Mon, 24 Jan 2022 10:36:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3AS82A2AfeuI; Mon, 24 Jan 2022 10:36:27 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 7A46C84B91; Mon, 24 Jan 2022 10:36:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5AAF5C0039; Mon, 24 Jan 2022 10:36:25 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0D874C002F for ; Mon, 24 Jan 2022 10:36:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 1353660E9C for ; Mon, 24 Jan 2022 10:35:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R0w6llQ56iXU for ; Mon, 24 Jan 2022 10:35:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 2E86860E6E for ; Mon, 24 Jan 2022 10:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nQH2FR2Vs8b2YQwJKWP+32fohC23/dvkv2wpb0R4JZA=; b=FYNn3FFGXxZ1gD/S38O7zo0nU0TcQrybO6TfcDic7wRM9TISB4fF+6eGTOQNXr422bhYF/ hGR41cWMgiemZ532wyC93p+0kgnWG1g8LCRZD7HraI5edCmpT/758Dbljv17agTMrRKs8z ieEAY7ARKZLiAncbqDWu4NNgE+0UCik= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-340-brroEiDdPkq53buW5p5SfQ-1; Mon, 24 Jan 2022 05:35:36 -0500 X-MC-Unique: brroEiDdPkq53buW5p5SfQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 08AEB1853024; Mon, 24 Jan 2022 10:35:35 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EA827A240; Mon, 24 Jan 2022 10:35:33 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:43 +0100 Message-Id: <20220124103445.2459400-12-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 11/13] hindex: remove the next variable in safe loops X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Apart from being safer from the point of view of potential undefined behavior, the multi-variable version of the safe iterators have the benefit of not requiring the declaration of an external variable to hold the next position. This patch removes the NEXT variable from all HINDEX_*_SAFE macros and all of its callers. Signed-off-by: Adrian Moreno --- lib/conntrack.c | 4 ++-- lib/hindex.h | 18 ++++++++---------- tests/test-hindex.c | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index 9c96b69e4..2f0777102 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -2857,8 +2857,8 @@ expectation_clean(struct conntrack *ct, const struct conn_key *parent_key) { ovs_rwlock_wrlock(&ct->resources_lock); - struct alg_exp_node *node, *next; - HINDEX_FOR_EACH_WITH_HASH_SAFE (node, next, node_ref, + struct alg_exp_node *node; + HINDEX_FOR_EACH_WITH_HASH_SAFE (node, node_ref, conn_key_hash(parent_key, ct->hash_basis), &ct->alg_expectation_refs) { if (!conn_key_cmp(&node->parent_key, parent_key)) { diff --git a/lib/hindex.h b/lib/hindex.h index 7b122744a..2c6e11120 100644 --- a/lib/hindex.h +++ b/lib/hindex.h @@ -134,13 +134,12 @@ void hindex_remove(struct hindex *, struct hindex_node *); /* Safe when NODE may be freed (not needed when NODE may be removed from the * hash map but its members remain accessible and intact). */ -#define HINDEX_FOR_EACH_WITH_HASH_SAFE(NODE, NEXT, MEMBER, HASH, HINDEX) \ - for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, \ - hindex_node_with_hash(HINDEX, HASH), \ - (void) NEXT); \ - CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL, \ - ITER_NEXT_VAR(NODE) = ITER_VAR(NODE)->s, \ - NODE, MEMBER); \ +#define HINDEX_FOR_EACH_WITH_HASH_SAFE(NODE, MEMBER, HASH, HINDEX) \ + for (INIT_MULTIVAR_SAFE(NODE, MEMBER, \ + hindex_node_with_hash(HINDEX, HASH)); \ + CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL, \ + ITER_NEXT_VAR(NODE) = ITER_VAR(NODE)->s, \ + NODE, MEMBER); \ UPDATE_MULTIVAR_SAFE(NODE)) /* Returns the head node in 'hindex' with the given 'hash', or a null pointer @@ -167,9 +166,8 @@ hindex_node_with_hash(const struct hindex *hindex, size_t hash) /* Safe when NODE may be freed (not needed when NODE may be removed from the * hash index but its members remain accessible and intact). */ -#define HINDEX_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HINDEX) \ - for (INIT_MULTIVAR_SAFE_EXP(NODE, MEMBER, hindex_first(HINDEX), \ - (void) NEXT); \ +#define HINDEX_FOR_EACH_SAFE(NODE, MEMBER, HINDEX) \ + for (INIT_MULTIVAR_SAFE(NODE, MEMBER, hindex_first(HINDEX)); \ CONDITION_MULTIVAR_SAFE(ITER_VAR(NODE) != NULL, \ ITER_NEXT_VAR(NODE) = hindex_next(HINDEX, ITER_VAR(NODE)), \ NODE, MEMBER); \ diff --git a/tests/test-hindex.c b/tests/test-hindex.c index af06be5fc..93b5308b2 100644 --- a/tests/test-hindex.c +++ b/tests/test-hindex.c @@ -256,7 +256,7 @@ test_hindex_for_each_safe(hash_func *hash) struct element elements[MAX_ELEMS]; int values[MAX_ELEMS]; struct hindex hindex; - struct element *e, *next; + struct element *e; size_t n_remaining; int i; @@ -264,7 +264,7 @@ test_hindex_for_each_safe(hash_func *hash) i = 0; n_remaining = n; - HINDEX_FOR_EACH_SAFE (e, next, node, &hindex) { + HINDEX_FOR_EACH_SAFE (e, node, &hindex) { assert(i < n); if (pattern & (1ul << e->value)) { size_t j; From patchwork Mon Jan 24 10:34:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583386 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dUJjwJEF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5xm2RPcz9t0k for ; Mon, 24 Jan 2022 21:36:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id F351A40ABE; Mon, 24 Jan 2022 10:36:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8fhOHDjBPSt5; Mon, 24 Jan 2022 10:36:23 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id BCBC040A9D; Mon, 24 Jan 2022 10:36:21 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7DF0FC0039; Mon, 24 Jan 2022 10:36:21 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1F220C007B for ; Mon, 24 Jan 2022 10:36:20 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 953E083F0E for ; Mon, 24 Jan 2022 10:35:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qkZnboSsoBAi for ; Mon, 24 Jan 2022 10:35:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 096FE84B33 for ; Mon, 24 Jan 2022 10:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OQiVwAc9EMqtgM26DDzdFFw4EmJQqdE3n6+d0d8zel8=; b=dUJjwJEFxm8gPshJ4OuCJ01WTEPVLsjQxbfChyWRPdhIxIbF+MOmG6+GIuTAmmPH3VipJH OZM8mr/LscaqS3P0ykhJgD7ikYQpfDAuPt28j+WrKxa5n3+nrJHmWs7BJoASegFSb4L8uy z+5BxgZJJYf2X4wizhlauj5fxbGwr8g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-594-CvvK7rmWMeO63VTPp3nX4w-1; Mon, 24 Jan 2022 05:35:38 -0500 X-MC-Unique: CvvK7rmWMeO63VTPp3nX4w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CAA11853028; Mon, 24 Jan 2022 10:35:37 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 738327A235; Mon, 24 Jan 2022 10:35:35 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:44 +0100 Message-Id: <20220124103445.2459400-13-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 12/13] rculist: use multi-variable helpers for loop macros X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Use multi-variable iteration helpers to rewrite rculist loops macros. There is an important behavior change compared with the previous implementation: When the loop ends normally (i.e: not via "break;"), the object pointer provided by the user is NULL. This is safer because it's not guaranteed that it would end up pointing a valid address. Signed-off-by: Adrian Moreno --- lib/rculist.h | 61 +++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/rculist.h b/lib/rculist.h index 1072b87af..01873700f 100644 --- a/lib/rculist.h +++ b/lib/rculist.h @@ -366,34 +366,37 @@ rculist_is_singleton_protected(const struct rculist *list) } #define RCULIST_FOR_EACH(ITER, MEMBER, RCULIST) \ - for (INIT_CONTAINER(ITER, rculist_next(RCULIST), MEMBER); \ - &(ITER)->MEMBER != (RCULIST); \ - ASSIGN_CONTAINER(ITER, rculist_next(&(ITER)->MEMBER), MEMBER)) -#define RCULIST_FOR_EACH_CONTINUE(ITER, MEMBER, RCULIST) \ - for (ASSIGN_CONTAINER(ITER, rculist_next(&(ITER)->MEMBER), MEMBER); \ - &(ITER)->MEMBER != (RCULIST); \ - ASSIGN_CONTAINER(ITER, rculist_next(&(ITER)->MEMBER), MEMBER)) - -#define RCULIST_FOR_EACH_REVERSE_PROTECTED(ITER, MEMBER, RCULIST) \ - for (INIT_CONTAINER(ITER, (RCULIST)->prev, MEMBER); \ - &(ITER)->MEMBER != (RCULIST); \ - ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER)) -#define RCULIST_FOR_EACH_REVERSE_PROTECTED_CONTINUE(ITER, MEMBER, RCULIST) \ - for (ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER); \ - &(ITER)->MEMBER != (RCULIST); \ - ASSIGN_CONTAINER(ITER, (ITER)->MEMBER.prev, MEMBER)) - -#define RCULIST_FOR_EACH_PROTECTED(ITER, MEMBER, RCULIST) \ - for (INIT_CONTAINER(ITER, rculist_next_protected(RCULIST), MEMBER); \ - &(ITER)->MEMBER != (RCULIST); \ - ASSIGN_CONTAINER(ITER, rculist_next_protected(&(ITER)->MEMBER), \ - MEMBER)) - -#define RCULIST_FOR_EACH_SAFE_PROTECTED(ITER, NEXT, MEMBER, RCULIST) \ - for (INIT_CONTAINER(ITER, rculist_next_protected(RCULIST), MEMBER); \ - (&(ITER)->MEMBER != (RCULIST) \ - ? INIT_CONTAINER(NEXT, rculist_next_protected(&(ITER)->MEMBER), \ - MEMBER), 1 : 0); \ - (ITER) = (NEXT)) + for (INIT_MULTIVAR(ITER, MEMBER, rculist_next(RCULIST)); \ + CONDITION_MULTIVAR(ITER_VAR(ITER) != (RCULIST), ITER, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(ITER) = rculist_next(ITER_VAR(ITER)), \ + ITER)) + +#define RCULIST_FOR_EACH_CONTINUE(ITER, MEMBER, RCULIST) \ + for (INIT_MULTIVAR(ITER, MEMBER, rculist_next(&(ITER)->MEMBER)); \ + CONDITION_MULTIVAR(ITER_VAR(ITER) != (RCULIST), ITER, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(ITER) = rculist_next(ITER_VAR(ITER)), \ + ITER)) + +#define RCULIST_FOR_EACH_REVERSE_PROTECTED(ITER, MEMBER, RCULIST) \ + for (INIT_MULTIVAR(ITER, MEMBER, (RCULIST)->prev); \ + CONDITION_MULTIVAR(ITER_VAR(ITER) != (RCULIST), ITER, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(ITER) = ITER_VAR(VAR).prev, ITER)) + +#define RCULIST_FOR_EACH_REVERSE_PROTECTED_CONTINUE(ITER, MEMBER, RCULIST) \ + for (INIT_MULTIVAR(ITER, MEMBER, (ITER)->MEMBER.prev); \ + CONDITION_MULTIVAR(ITER_VAR(ITER) != (RCULIST), ITER, MEMBER); \ + UPDATE_MULTIVAR(ITER_VAR(ITER) = ITER_VAR(VAR).prev, ITER)) + +#define RCULIST_FOR_EACH_PROTECTED(ITER, MEMBER, RCULIST) \ + for (INIT_MULTIVAR(ITER, MEMBER, rculist_next_protected(RCULIST)); \ + CONDITION_MULTIVAR(ITER_VAR(ITER) != (RCULIST), ITER, MEMBER); \ + UPDATE_MULTIVAR(rculist_next_protected(ITER_VAR(ITER), ITER)) \ + +#define RCULIST_FOR_EACH_SAFE_PROTECTED(ITER, MEMBER, RCULIST) \ + for (INIT_MULTIVAR_SAFE(ITER, MEMBER, rculist_next_protected(RCULIST)); \ + CONDITION_MULTIVAR_SAFE(ITER_VAR(ITER) != (RCULIST), \ + ITER_NEXT_VAR(ITER) = rculist_next_protected(ITER_VAR(VAR)), \ + ITER, MEMBER); \ + UPDATE_MULTIVAR(ITER)) #endif /* rculist.h */ From patchwork Mon Jan 24 10:34:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 1583385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=jAEBFLkW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jj5xd4sY7z9t0k for ; Mon, 24 Jan 2022 21:36:21 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7806D84B84; Mon, 24 Jan 2022 10:36:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A3cR4Z9hjRA3; Mon, 24 Jan 2022 10:36:18 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 9533684B7A; Mon, 24 Jan 2022 10:36:17 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7157EC0039; Mon, 24 Jan 2022 10:36:17 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2B258C002F for ; Mon, 24 Jan 2022 10:36:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 0131B83EE8 for ; Mon, 24 Jan 2022 10:35:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YTNYNIeuaH39 for ; Mon, 24 Jan 2022 10:35:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id E939D83F86 for ; Mon, 24 Jan 2022 10:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643020541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KwylGc69Xo+NpqTYyBpXRJn+Rxuk0bqRBLlnmwo5mJ4=; b=jAEBFLkWS+MVXFqm6EWS1lkWNhDlzoyzNW3fk29E1++X21ZPprAB3LNRp0xZhrEHEpGaoj l2Fw305QHAYYS6hyqUZNWbrscOBjb/s+B/DU/U2Nf9kUqrbKrIz4akeMRXFKv9zsk8jw1X dIHBa6gopoZ2gX7sUB16NKpFJkEeCus= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-642-UQGkj3KHN2uRJHDb7oMqAw-1; Mon, 24 Jan 2022 05:35:40 -0500 X-MC-Unique: UQGkj3KHN2uRJHDb7oMqAw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA1FA80F041; Mon, 24 Jan 2022 10:35:39 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (unknown [10.39.193.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCEC27A235; Mon, 24 Jan 2022 10:35:37 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Mon, 24 Jan 2022 11:34:45 +0100 Message-Id: <20220124103445.2459400-14-amorenoz@redhat.com> In-Reply-To: <20220124103445.2459400-1-amorenoz@redhat.com> References: <20220124103445.2459400-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: jakub@redhat.com, fweimer@redhat.com, dceara@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 13/13] vtep: use _SAFE iterator if freing the iterator X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" The _SAFE version of the iterator allows the user to free the iterator structure safely. Signed-off-by: Adrian Moreno --- vtep/vtep-ctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c index 99c4adcd5..685b0007a 100644 --- a/vtep/vtep-ctl.c +++ b/vtep/vtep-ctl.c @@ -738,7 +738,7 @@ del_ploc_from_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac, { struct vtep_ctl_ploc *ploc; - LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) { + LIST_FOR_EACH_SAFE (ploc, locators_node, &mcast_mac->locators) { if (ploc->ploc_cfg == ploc_cfg) { ovs_list_remove(&ploc->locators_node); free(ploc);