Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2027590pxf; Sat, 27 Mar 2021 00:26:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzZPYMBWsY8sj+OvCJzMcMZtgbAM05/dr3xbmkzGAt//JBUcLydHzE7LzXRorM+JMfvWcY X-Received: by 2002:a17:906:7f01:: with SMTP id d1mr19523227ejr.136.1616829967920; Sat, 27 Mar 2021 00:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616829967; cv=none; d=google.com; s=arc-20160816; b=eWUNpNNEXGzsoB9AMV2Ufu8B9se+tJzGnz8Sp947G5ka5qyZj5TA1JYuo2AiUEi2wm F74UPOZrGTvFwW0zWNJQ+O6hffGSbG4j5Ca2L9iZzmir6fCbrt3LXTrVFEMAfmb0PgNl bc65X+C7xsetFQrzGKcVWmoV9ytyQSmtdzNwsEUjcuuFDfFYJNIK9a0NHDwID/CZEJ99 6kRAB2AYMLrEdtqkorFu8dXos+GgTPAT4vBocYH3JlDh3bokBk/bY4EAYtzpdJ7UCJQp WMPyUrECxDRf/fWPLBvhP6ahB6VpW2ni4e/FAnbV2lQgG72AiCsLRs3TLM/hOFfm3UqR iH1A== 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=heqbHYASbfXDp78dxRgzjGGAeQKmpbwMjg9AIXYIdwI=; b=z5N6xylw6oRpmoLbjX8BFPQVkpEG7fFFwB9XKJMfRsF6MPu/o9Sp9vpRYy6Ry4IBOd MqeYFL962GoVw6qY9LahupgyxvIdV0/w5mr64S3IEZ2Y8FH7dKWMqGGRLLf2skeOfJyr wO1VpRZDSbcTUOtegMf/qC6X3ipTt/WPy5lqkwQM5hmuxOHXHwP46u4ONgowA0kfRWif /SkODgxI+5afpcorZaNxaHS0JblywwHC3N33hcJGoGlsy9n14WdI1o6t2Cs4IimTufGu 6aCI5yE6Cmkr+MdC0RE0y3cwfMv3c1dVC017TweblULjjNq2nXhindxkrKsnsOnvhEGR NnBg== 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 s9si8375978edc.296.2021.03.27.00.25.37; Sat, 27 Mar 2021 00:26:07 -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 S230238AbhC0HQ6 (ORCPT + 99 others); Sat, 27 Mar 2021 03:16:58 -0400 Received: from mail-m17637.qiye.163.com ([59.111.176.37]:59816 "EHLO mail-m17637.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbhC0HQ4 (ORCPT ); Sat, 27 Mar 2021 03:16:56 -0400 Received: from wanjb-virtual-machine.localdomain (unknown [36.152.145.182]) by mail-m17637.qiye.163.com (Hmail) with ESMTPA id AE1D098014B; Sat, 27 Mar 2021 15:16:52 +0800 (CST) From: Wan Jiabing To: Wan Jiabing , linux-kernel@vger.kernel.org Cc: kael_w@yeah.net Subject: [PATCH] scripts: checkdeclares for checking duplicate struct declares Date: Sat, 27 Mar 2021 15:16:36 +0800 Message-Id: <20210327071641.1485896-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 oVCBIfWUFZGk9IH0NKGk0YTRhNVkpNSk1DSUJPSklDTU1VEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS0hKTFVLWQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MC46SAw6FD8IFjNLMgkyFwE1 Pw9PFBFVSlVKTUpNQ0lCT0pISUtIVTMWGhIXVQwaFRESGhkSFRw7DRINFFUYFBZFWVdZEgtZQVlI TVVKTklVSk9OVUpDSVlXWQgBWUFJTUJINwY+ X-HM-Tid: 0a78728af5bdd992kuwsae1d098014b 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 | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 scripts/checkdeclares.pl diff --git a/scripts/checkdeclares.pl b/scripts/checkdeclares.pl new file mode 100755 index 000000000000..f28c40ab0f00 --- /dev/null +++ b/scripts/checkdeclares.pl @@ -0,0 +1,55 @@ +#!/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 %declaredfiles = (); + my @file_lines = (); + + while (<$f>) { + if (m/^\s*struct\s*(\w*);$/o) { + ++$declaredfiles{$1}; + } + push(@file_lines, $_); + } + + close($f); + + foreach my $filename (keys %declaredfiles) { + if ($declaredfiles{$filename} > 1) { + print "$file: struct $filename is declared more than once.\n"; + ++$dup_counter; + } + } +} + +if ($dup_counter == 0) { + print "No duplicate struct declares found.\n"; +} -- 2.25.1