Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp726649pxf; Thu, 1 Apr 2021 11:55:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpaZ4k5XikhmwfeBFNDxE2rXTwcJr0tSwCnqREtrG/+9rsP9OVxAg6oGAoNXcMfeX28/4o X-Received: by 2002:a17:907:c08:: with SMTP id ga8mr10514813ejc.376.1617303358250; Thu, 01 Apr 2021 11:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617303358; cv=none; d=google.com; s=arc-20160816; b=xBcezyYvz/rRFXB2Z+sIwIQt/0VJTJw0Qf9UJa6r2l23Dr+OpY9nIz1u3JH2STK9i7 FxttobiKWNB9fHacb3gFxVDueNYPg0XGG9Y3Nit+ZoqONw+xwMDLQ2xo2oecrb9nW+qq 4SdzXrEdmQ1+xyrEEgvIbwnm+in9+zE5HCwuYO29ntSxeP++btGokCYBXKTifQTAB2oZ 0L/y+TlJUaFe3FDqwoM6iaLT2sylvlg7ygrmLOs7FUdOZG4WYlTc4lci3y6z+D3Qm0cd qS6f99jMQsH1CkO49SDPK/u8csd3xxscd/nLt+3Lo641N/IkTTgx+ogEnO4+/hHtPEon 2Lqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=qyxAf++wFrgL7XprRw1HJtrKWHgu/BIROVX+IyUuMQg=; b=NoR8sL/z0yINbghq2u29IleSKpMw74un/iu/QxPvU598U5WLkqh6gz6mUiKcqIWjLJ kreYe8A4beY5coBinaGvTIbcDWuuvI/Rtm0LosRX4nUeWhy9w7dcrJOO4BwX6FeWUcRu 7cJW36MPBfZewYXFojX2x7Tzd8JF1BnbIm66R70pdkodj5w8/AVlkk0IN2q9h7eRQp0b kwG+6N3jqOafsOKFQRAW5HGQZlBTlOYFrdy3/hbjRR1ZFiu5cZnuHEGyXjNXxESObLeI YNy7pBjiH7lxZDZZRnqXYvlQeF+8F/A/ShHKqDPpZNiolN/mC4aqvKxbsEvcbA8BSZMU v0CQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vivo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b14si4844031eds.379.2021.04.01.11.55.35; Thu, 01 Apr 2021 11:55:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239248AbhDASut (ORCPT + 99 others); Thu, 1 Apr 2021 14:50:49 -0400 Received: from mail-m17637.qiye.163.com ([59.111.176.37]:17444 "EHLO mail-m17637.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240683AbhDASbJ (ORCPT ); Thu, 1 Apr 2021 14:31:09 -0400 Received: from wanjb-virtual-machine.localdomain (unknown [36.152.145.182]) by mail-m17637.qiye.163.com (Hmail) with ESMTPA id 9AFE59800C3; Thu, 1 Apr 2021 19:09:51 +0800 (CST) From: Wan Jiabing To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org Cc: kael_w@yeah.net, Wan Jiabing Subject: [PATCH] scripts: A new script for checking duplicate struct declaration Date: Thu, 1 Apr 2021 19:09:43 +0800 Message-Id: <20210401110943.1010796-1-wanjiabing@vivo.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZTUxKTEJKQ0wYT0lLVkpNSkxJTE5IQkpDSkJVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS0NJQ1VLWQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NzI6Pxw4Tj8SFisMIzM0MkJC HzAwFEtVSlVKTUpMSUxOSEJJS05DVTMWGhIXVQwaFRESGhkSFRw7DRINFFUYFBZFWVdZEgtZQVlI TVVKTklVSk9OVUpDSVlXWQgBWUFJTEpDNwY+ X-HM-Tid: 0a788d200efbd992kuws9afe59800c3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org checkdeclares: find struct declared more than once. Inspired by checkincludes.pl. This script checks for duplicate struct declares. Note that this will not take into consideration macros, so you should run this only if you know you do have real dups and do not have them under #ifdef's. You could also just review the results. Signed-off-by: Wan Jiabing --- scripts/checkdeclares.pl | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 scripts/checkdeclares.pl diff --git a/scripts/checkdeclares.pl b/scripts/checkdeclares.pl new file mode 100755 index 000000000000..d14a8cc39a4d --- /dev/null +++ b/scripts/checkdeclares.pl @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 +# +# checkdeclares: find struct declared more than once +# +# Copyright 2021 Wan Jiabing +# Inspired by checkincludes.pl +# +# This script checks for duplicate struct declares. +# Note that this will not take into consideration macros so +# you should run this only if you know you do have real dups +# and do not have them under #ifdef's. +# You could also just review the results. + +use strict; + +sub usage { + print "Usage: checkdeclares.pl \n"; + print "We just warn of struct declaration duplicates\n"; + exit 1; +} + +if ($#ARGV < 0) { + usage(); +} + +my $dup_counter = 0; + +foreach my $file (@ARGV) { + open(my $f, '<', $file) + or die "Cannot open $file: $!.\n"; + + my %declaredstructs = (); + + while (<$f>) { + if (m/^\s*struct\s*(\w*);$/o) { + ++$declaredstructs{$1}; + } + } + + close($f); + + foreach my $structname (keys %declaredstructs) { + if ($declaredstructs{$structname} > 1) { + print "$file: struct $structname is declared more than once.\n"; + ++$dup_counter; + } + } +} + +if ($dup_counter == 0) { + print "No duplicate struct declares found.\n"; +} -- 2.25.1