From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 71052A034E; Wed, 9 Feb 2022 20:18:08 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B79864115B; Wed, 9 Feb 2022 20:17:57 +0100 (CET) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id 86C074114F for ; Wed, 9 Feb 2022 20:17:54 +0100 (CET) Received: by mail-pf1-f181.google.com with SMTP id i6so4067043pfc.9 for ; Wed, 09 Feb 2022 11:17:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y1KAqCayHjeArGHVHj6SXBibsv0kgr3PuI+KNYWbqHw=; b=kzhM0iLaJ+Mu/2OTUu3qLpYXhqdZfGn8OWfHdzoXtAfahn6zXoXS6ClDTdYKNz0QVQ n01oAWd2dZJ098i85kMbZ5hAksOXJTmNfGtyOUoa9VfuVgIA8j4LAKQEGbvDelGvOu29 Bu884xuagPrqzFr+TeQrkehXjUllFtDlhUDrvs+NSrYjeT/FiRLcPgZrlkFWaAM8RnAL vbl27UtkZoHLFQoy/7nsUv1NMFplzl1yEIT/9fVW97bhrqiVwZI0ddZ4Dhf/v09oebKK e50vqGJkkY4GtGIOrHgcCFDcX4ZUtMUhTg4o3PaWMFV9EYV6RIx9iqTNXxlHfMtUHiNH wu3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y1KAqCayHjeArGHVHj6SXBibsv0kgr3PuI+KNYWbqHw=; b=Q+33Arfc4BjNgDxtMy1qCOS1GwJ1gouS84RhkZeoDbpC9DF2MbFg+tf3gF3yqY5VqH mp5TPWTcCmZnsDDqF8Gs0h1py8tgpSM+imq174kbxFiu/4emoADejUt+45b3e2x384BV PdHhwwneyQ9wjBP0Ll7aSRZ7yy63YQBlpDiRgq5q7eJaUd0Uqv4MTLgqJ7I+PHwfQROf GPcTLHbSQLDib43OCdLlE7OCEhjX5fNPHN4br3CcXsFX14Sqd5aDgGyQaXMsectYcvfm 0Xd6goRypV9FUShC7FRKWbWvNFlbbFaKCul7Ic6ycmS88tkUtDmGW45JCSx+o9pGTJnj Mqag== X-Gm-Message-State: AOAM533thncJK6TsSkqY6c47uNT2maPq2Vw+AEdy0kEUoUrrb4L0De5v sYwTAuTCzmYqWjiH4W6P++C0C6T/OZDSM34R X-Google-Smtp-Source: ABdhPJy9nDnVGqQjoV3Gu4TvLaQXQK43oLJskxLcNdG3TWEVikr+Dpu4b+RT3d3lJXXZIE6fheQ4wg== X-Received: by 2002:a63:8343:: with SMTP id h64mr3061027pge.547.1644434273514; Wed, 09 Feb 2022 11:17:53 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id u16sm14378401pgh.54.2022.02.09.11.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 11:17:52 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v3 02/36] devtools/cocci: add script to fix unnecessary null checks Date: Wed, 9 Feb 2022 11:17:14 -0800 Message-Id: <20220209191748.377729-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220209191748.377729-1-stephen@networkplumber.org> References: <20220124000518.319850-1-stephen@networkplumber.org> <20220209191748.377729-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This script is based on the idea of the nullfree script in the Linux kernel. It finds cases where a check for null pointer is done, but is unnecessary because the function already handles NULL pointer. Basic example: if (x->buf) rte_free(x->buf); can be reduced to: rte_free(x->buf); Signed-off-by: Stephen Hemminger --- devtools/cocci/nullfree.cocci | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 devtools/cocci/nullfree.cocci diff --git a/devtools/cocci/nullfree.cocci b/devtools/cocci/nullfree.cocci new file mode 100644 index 000000000000..363b6149ac28 --- /dev/null +++ b/devtools/cocci/nullfree.cocci @@ -0,0 +1,33 @@ +// +// Remove unnecessary NULL pointer checks before free functions +// All these functions work like libc free which allows +// free(NULL) as a no-op. +// +@@ +expression E; +@@ +( +- if (E != NULL) free(E); ++ free(E); +| +- if (E != NULL) rte_bitmap_free(E); ++ rte_bitmap_free(E); +| +- if (E != NULL) rte_free(E); ++ rte_free(E); +| +- if (E != NULL) rte_hash_free(E); ++ rte_hash_free(E); +| +- if (E != NULL) rte_ring_free(E); ++ rte_ring_free(E); +| +- if (E != NULL) rte_pktmbuf_free(E); ++ rte_pktmbuf_free(E); +| +- if (E != NULL) rte_mempool_free(E); ++ rte_mempool_free(E); +| +- if (E != NULL) rte_kvargs_free(E); ++ rte_kvargs_free(E); +) -- 2.34.1