From patchwork Thu Jan 4 14:28:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1882479 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=QHAsCf7V; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T5TVV2T02z23dg for ; Fri, 5 Jan 2024 01:29:06 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 63F8D82BC8; Thu, 4 Jan 2024 14:29:02 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 63F8D82BC8 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QHAsCf7V 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 wsRWxZrue_si; Thu, 4 Jan 2024 14:29:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 72799823AA; Thu, 4 Jan 2024 14:29:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 72799823AA Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 29606C0072; Thu, 4 Jan 2024 14:29:00 +0000 (UTC) X-Original-To: ovs-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 EA7AEC0037 for ; Thu, 4 Jan 2024 14:28:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id B8C8041BA8 for ; Thu, 4 Jan 2024 14:28:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B8C8041BA8 Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QHAsCf7V 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 FCtTzbcjcUyF for ; Thu, 4 Jan 2024 14:28:58 +0000 (UTC) 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 CE34341BA3 for ; Thu, 4 Jan 2024 14:28:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org CE34341BA3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704378536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nffYZ5y8ZNHwGc1Y7lSy+5P5EoWNyJrw93y7+2UU6RQ=; b=QHAsCf7V+PH1HLMujsVwd9LiAurmavgX1WVSPsWrdWvOFdpYGZVSanNe/VOsKFiaVATT+D AQHf0PmBojrWu/HYOiwSXSnvvFx9A/u9v9bUKVG++nTmLVpNJRFtq/KIXKfkbPpPGCwDf5 F1qtmSh3l/CUS2PX/tfj6+7rsU4jtcQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-UEogO9RpNkC7AwY2sMcdOA-1; Thu, 04 Jan 2024 09:28:50 -0500 X-MC-Unique: UEogO9RpNkC7AwY2sMcdOA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE73A3C025D1 for ; Thu, 4 Jan 2024 14:28:49 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D239492BC7 for ; Thu, 4 Jan 2024 14:28:48 +0000 (UTC) From: Dumitru Ceara To: ovs-dev@openvswitch.org Date: Thu, 4 Jan 2024 15:28:45 +0100 Message-Id: <20240104142845.205691-1-dceara@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn] treewide: Cleanup free() calls. 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" It's perfectly fine to call free(NULL). Take advantage of that to simplify the code. Use the safer CONST_CAST way of "unconsting" pointers we pass to free while we're at it. Signed-off-by: Dumitru Ceara Acked-by: Ales Musil --- controller/ovn-controller.c | 12 +++--------- controller/pinctrl.c | 5 +---- controller/vif-plug.c | 12 +++--------- lib/expr.c | 22 ++++++++-------------- lib/ovn-parallel-hmap.c | 6 ++---- northd/ipam.c | 2 +- 6 files changed, 18 insertions(+), 41 deletions(-) diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 760b7788be..8709c1ae2a 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -688,9 +688,7 @@ add_pending_ct_zone_entry(struct shash *pending_ct_zones, */ struct ct_zone_pending_entry *existing = shash_replace(pending_ct_zones, name, pending); - if (existing) { - free(existing); - } + free(existing); } static bool @@ -6099,12 +6097,8 @@ loop_done: ovs_feature_support_destroy(); free(ovs_remote); - if (file_system_id) { - free(file_system_id); - } - if (cli_system_id) { - free(cli_system_id); - } + free(file_system_id); + free(cli_system_id); ovn_exit_args_finish(&exit_args); unixctl_server_destroy(unixctl); service_stop(); diff --git a/controller/pinctrl.c b/controller/pinctrl.c index 5a35d56f6b..12055a6756 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -1282,10 +1282,7 @@ fill_ipv6_prefix_state(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ipv6_prefixd_state *pfd; if (!smap_get_bool(&pb->options, "ipv6_prefix", false)) { - pfd = shash_find_and_delete(&ipv6_prefixd, pb->logical_port); - if (pfd) { - free(pfd); - } + free(shash_find_and_delete(&ipv6_prefixd, pb->logical_port)); continue; } diff --git a/controller/vif-plug.c b/controller/vif-plug.c index 38348bf544..d4c7552eab 100644 --- a/controller/vif-plug.c +++ b/controller/vif-plug.c @@ -142,15 +142,9 @@ destroy_port_ctx(struct vif_plug_port_ctx *ctx) { smap_destroy(&ctx->vif_plug_port_ctx_in.lport_options); smap_destroy(&ctx->vif_plug_port_ctx_in.iface_options); - if (ctx->vif_plug_port_ctx_in.lport_name) { - free((char *)ctx->vif_plug_port_ctx_in.lport_name); - } - if (ctx->vif_plug_port_ctx_in.iface_name) { - free((char *)ctx->vif_plug_port_ctx_in.iface_name); - } - if (ctx->vif_plug_port_ctx_in.iface_type) { - free((char *)ctx->vif_plug_port_ctx_in.iface_type); - } + free(CONST_CAST(char *, ctx->vif_plug_port_ctx_in.lport_name)); + free(CONST_CAST(char *, ctx->vif_plug_port_ctx_in.iface_name)); + free(CONST_CAST(char *, ctx->vif_plug_port_ctx_in.iface_type)); /* Note that data associated with ctx->vif_plug_port_ctx_out must be * destroyed by the plug provider implementation with a call to * vif_plug_port_ctx_destroy prior to calling this function */ diff --git a/lib/expr.c b/lib/expr.c index f5d2032334..0cb44e1b6f 100644 --- a/lib/expr.c +++ b/lib/expr.c @@ -179,17 +179,13 @@ expr_combine(enum expr_type type, struct expr *a, struct expr *b) } else { ovs_list_push_back(&a->andor, &b->node); } - if (a->as_name) { - free(a->as_name); - a->as_name = NULL; - } + free(a->as_name); + a->as_name = NULL; return a; } else if (b->type == type) { ovs_list_push_front(&b->andor, &a->node); - if (b->as_name) { - free(b->as_name); - b->as_name = NULL; - } + free(b->as_name); + b->as_name = NULL; return b; } else { struct expr *e = expr_create_andor(type); @@ -879,12 +875,10 @@ parse_constant(struct expr_context *ctx, struct expr_constant_set *cs, sizeof *cs->values); } - if (cs->as_name) { - /* Combining other values to the constant set that is tracking an - * address set, so untrack it. */ - free(cs->as_name); - cs->as_name = NULL; - } + /* Combining other values to the constant set that is tracking an + * address set, so untrack it. */ + free(cs->as_name); + cs->as_name = NULL; if (ctx->lexer->token.type == LEX_T_TEMPLATE) { lexer_error(ctx->lexer, "Unexpanded template."); diff --git a/lib/ovn-parallel-hmap.c b/lib/ovn-parallel-hmap.c index a0ba681a1e..1b167e2145 100644 --- a/lib/ovn-parallel-hmap.c +++ b/lib/ovn-parallel-hmap.c @@ -427,10 +427,8 @@ ovn_update_hashrow_locks(struct hmap *lflows, struct hashrow_locks *hrl) { int i; if (hrl->mask != lflows->mask) { - if (hrl->row_locks) { - free(hrl->row_locks); - } - hrl->row_locks = xcalloc(sizeof(struct ovs_mutex), lflows->mask + 1); + hrl->row_locks = xrealloc(hrl->row_locks, + sizeof *hrl->row_locks * (lflows->mask + 1)); hrl->mask = lflows->mask; for (i = 0; i <= lflows->mask; i++) { ovs_mutex_init(&hrl->row_locks[i]); diff --git a/northd/ipam.c b/northd/ipam.c index 68a757098b..4448a76074 100644 --- a/northd/ipam.c +++ b/northd/ipam.c @@ -44,7 +44,7 @@ void destroy_ipam_info(struct ipam_info *info) { bitmap_free(info->allocated_ipv4s); - free((char *) info->id); + free(CONST_CAST(char *, info->id)); } bool