From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A01DC433DF for ; Fri, 16 Oct 2020 02:49:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1798B20E65 for ; Fri, 16 Oct 2020 02:49:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="kiXG9M5N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1798B20E65 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9C5EF940065; Thu, 15 Oct 2020 22:49:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94EE4940034; Thu, 15 Oct 2020 22:49:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83E83940065; Thu, 15 Oct 2020 22:49:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 5455A940034 for ; Thu, 15 Oct 2020 22:49:03 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F02F7181AEF00 for ; Fri, 16 Oct 2020 02:49:02 +0000 (UTC) X-FDA: 77376256524.22.place98_1714af527219 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id C7C8A18038E60 for ; Fri, 16 Oct 2020 02:49:02 +0000 (UTC) X-HE-Tag: place98_1714af527219 X-Filterd-Recvd-Size: 3202 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Fri, 16 Oct 2020 02:49:02 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 022352087D; Fri, 16 Oct 2020 02:49:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602816541; bh=+zm8JEJDvdWTDvYHkQ5bHIwYYLcmpSp2CxNSfmGjWws=; h=Date:From:To:Subject:In-Reply-To:From; b=kiXG9M5NrbbXRXdX9LveyBaWtLGecVydxaunLwI3St1a4IdpqVOl/VA5CK5p09S1N emLqiax+hZWviK1o3ZfnMW00nd0iNIn66GnkACH4TlddqdVVsHImhSp0lZX8kBEx5M cLCNTzOkS0GVkIJ5K9nwCUQ1pJ1CKV3vk4WXoHPA= Date: Thu, 15 Oct 2020 19:49:00 -0700 From: Andrew Morton To: akpm@linux-foundation.org, efremov@linux.com, gustavoars@kernel.org, joe@perches.com, julia.lawall@inria.fr, keescook@chromium.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 127/156] checkpatch: warn on self-assignments Message-ID: <20201016024900.rKnqH0xK7%akpm@linux-foundation.org> In-Reply-To: <20201015192732.f448da14e9854c7cb7299956@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Joe Perches Subject: checkpatch: warn on self-assignments The uninitialized_var() macro was removed recently via commit 63a0895d960a ("compiler: Remove uninitialized_var() macro") as it's not a particularly useful warning and its use can "paper over real bugs". Add a checkpatch test to warn on self-assignments as a means to avoid compiler warnings and as a back-door mechanism to reproduce the old uninitialized_var macro behavior. [akpm@linux-foundation.org: coding style fixes] Link: https://lkml.kernel.org/r/afc2cffdd315d3e4394af149278df9e8af7f49f4.camel@perches.com Signed-off-by: Joe Perches Cc: Kees Cook Cc: Gustavo A. R. Silva Cc: Denis Efremov Cc: Julia Lawall Signed-off-by: Andrew Morton --- scripts/checkpatch.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/scripts/checkpatch.pl~checkpatch-warn-on-self-assignments +++ a/scripts/checkpatch.pl @@ -3899,6 +3899,17 @@ sub process { #ignore lines not being added next if ($line =~ /^[^\+]/); +# check for self assignments used to avoid compiler warnings +# e.g.: int foo = foo, *bar = NULL; +# struct foo bar = *(&(bar)); + if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) { + my $var = $1; + if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) { + WARN("SELF_ASSIGNMENT", + "Do not use self-assignments to avoid compiler warnings\n" . $herecurr); + } + } + # check for dereferences that span multiple lines if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ && $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) { _