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 4CF3AA04A6; Mon, 24 Jan 2022 01:05:30 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A1417427AF; Mon, 24 Jan 2022 01:05:25 +0100 (CET) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mails.dpdk.org (Postfix) with ESMTP id 62FDB40040 for ; Mon, 24 Jan 2022 01:05:23 +0100 (CET) Received: by mail-pl1-f179.google.com with SMTP id c9so13905876plg.11 for ; Sun, 23 Jan 2022 16:05:23 -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=lITO3Kqqs+aJDmQXmNqdZndLVIM4kiX6U7jq5x2Qwgc=; b=EOHdMVYMsbn6ap0AslbU8ne2uWLq+K9Nb2W5sd3sQOVeARbRrK6iRTfvFmUyMFi6NM 6qLz10IFNDQiBjl42E1SgFLPaEGZ8Ts9VshIQgehxz7NEHNjqMBbsAZi1OhMAtP/jpxx HVn/QfG2L4ENz1GXTTgRlvRtB55UzQxxbWNVVux41jDD3zdsrUtnGoinu6VOq+F8Y8qi ytpuMkUC+0ON8Ty6ae8n6DPfKy30TMMtsyuZvL4NxIjhBG3IEpP2lJ9wnHKQE/h7tfQ1 NqAQfSmxcJmGJkN6Kc8hf6w357VZYklOXrzyzbGc5/dAPKlWzciSP6qv7AOm8pwRs11F ETKw== 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=lITO3Kqqs+aJDmQXmNqdZndLVIM4kiX6U7jq5x2Qwgc=; b=5bvYg7HxnmqWByql+NY8PGZEQMg/hE1S+DIG6WuyhB8U6eGgSrlhg8KD5HB7WHB/4N 4Sl8fVjAts4TticgTDjyr7HH1RKv9S+EROxuC+hZ3DaBzmn1Xa9WsKo6NdrKqliC6xpU 6kcWSWrDAlWgJWWGjxGH+JeTDByxvWOEImDBpiu20/YPtoOrpLGGP/r7RcNGaYjj8WOy Fc71g1+ff+DPN1URYq5ELFoVFrufAnu0ogBnLSCVCruEC4OAdN8UVN53DcqWe15o9d8q nZLl3JayIO5untKVkfpPSPX7YXXGGHTXCGry2btOJrgUZBZ75NeXcJQtJmeMejQRtxa0 SXWA== X-Gm-Message-State: AOAM532c9ZLBrGr5xTnmw+TxXoBAyVA4JRhvl1RuMpq3mi5YnZVZvzey mJa+FMrxb6kcjLIVrGhxrwQTTEkRQ/ZJ1Q== X-Google-Smtp-Source: ABdhPJySqdU4whKgC/pqWH93q0F12el9SXaDti4Jh1sUaN5LbE9t/nwqwQ/svp9ojzB/Tz+D1VaaAg== X-Received: by 2002:a17:90b:1909:: with SMTP id mp9mr6802970pjb.53.1642982722356; Sun, 23 Jan 2022 16:05:22 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id ck21sm10935350pjb.51.2022.01.23.16.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jan 2022 16:05:21 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH 01/82] devtools/cocci: add script to fix unnecessary null checks Date: Sun, 23 Jan 2022 16:03:57 -0800 Message-Id: <20220124000518.319850-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124000518.319850-1-stephen@networkplumber.org> References: <20220124000518.319850-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 unneccessary 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.30.2