Message ID | 20230129094242.282620-1-liaochang1@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1689242wrn; Sun, 29 Jan 2023 02:20:01 -0800 (PST) X-Google-Smtp-Source: AK7set/2k5+N4E+NLcO815sJ6OsgCjjkHEkC27N38k7POclT9IYrulqyLPleS2roHkQv4TwnwOHn X-Received: by 2002:a17:90b:4b09:b0:22c:19a6:1c07 with SMTP id lx9-20020a17090b4b0900b0022c19a61c07mr5647683pjb.16.1674987601097; Sun, 29 Jan 2023 02:20:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674987601; cv=none; d=google.com; s=arc-20160816; b=dloUH8jh14/Cl8M9YPZrjhHcrfBOBL3wja/IikWMLAijlvoQ5JH+5Nmt9P2gxH3SrY Gnd/kYh5WSuAvZnVGo3ZAQCpSyhsOJowSk7YJhYJJnyJex3c73aJj0wv43lXWQl+jG/p VTH81uyrTQIvi8lJK27WjQ1xBTpVQiYjsJW42U9muJhyd7oTvLPR5w65Tm+MfGUifoYz hodGnsM6a+og4B8ORxJX2VGT9Ne1GrD/MpPXV+jLrrvOMRZGakoQ51u3HTCburCOsbDV 2UxFlEnNGzdUiyB8oXld1cnNedJFUOXgRdp33/UhIjeACTxJgG34+uFbBOMCIfJdcqrU 5iSg== 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=mF4WLAYWswgvLQyWpDiRTPJx/OxN4H0WtP8sXKCD7gA=; b=GAPPflgEE5555wpTVC1PP2XgBFOb6qT7PljYbkziPVShEzAV4nFNj2o3myQH/khT+g 1S/UbDCtfrUYqCsm1iWWTmmW8pWkhKn67ygNLm1FczA7Xectdj/nq/ti/HWk/djLopeG q+qgTzCklyNOeyX66R7OLARu61U4Ca/347M2Upz760dFOom4e3zbPY/uJWB3G5AGmUOw HzGAi7tGvRuFfqnL07fdV7ytuDAFr3CLVrOTadMoziOzLFFXBpJlKp0bg02vvDE4BdCy LjxBCku+KTf9OSQMSRSDmuZD2NgpPa8iCtH0dF8zJ92SJQId6RsdY5rUhGeu9zX9o1S8 hEzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020a17090a62c100b0022bf88769b8si9842158pjs.170.2023.01.29.02.19.48; Sun, 29 Jan 2023 02:20:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233855AbjA2JpI (ORCPT <rfc822;n2h9z4@gmail.com> + 99 others); Sun, 29 Jan 2023 04:45:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbjA2JpG (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 29 Jan 2023 04:45:06 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 486C430DA for <linux-kernel@vger.kernel.org>; Sun, 29 Jan 2023 01:45:05 -0800 (PST) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4P4RFP1c9lz16N2W; Sun, 29 Jan 2023 17:43:05 +0800 (CST) Received: from huawei.com (10.67.174.53) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sun, 29 Jan 2023 17:45:02 +0800 From: Liao Chang <liaochang1@huawei.com> To: <paul.walmsley@sifive.com>, <palmer@dabbelt.com>, <aou@eecs.berkeley.edu>, <heiko.stuebner@vrull.eu>, <ajones@ventanamicro.com>, <prabhakar.mahadev-lad.rj@bp.renesas.com>, <conor.dooley@microchip.com>, <jszhang@kernel.org>, <liaochang1@huawei.com>, <vincent.chen@sifive.com> CC: <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH] riscv: Add header include guards to insn.h Date: Sun, 29 Jan 2023 17:42:42 +0800 Message-ID: <20230129094242.282620-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756351798947306540?= X-GMAIL-MSGID: =?utf-8?q?1756351798947306540?= |
Series |
riscv: Add header include guards to insn.h
|
|
Commit Message
Liao Chang
Jan. 29, 2023, 9:42 a.m. UTC
Add header include guards to insn.h to prevent repeating declaration of
any identifiers in insn.h.
Fixes: edde5584c7ab ("riscv: Add SW single-step support for KDB")
Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
arch/riscv/include/asm/insn.h | 4 ++++
1 file changed, 4 insertions(+)
Comments
On Sun, Jan 29, 2023 at 05:42:42PM +0800, Liao Chang wrote: > Add header include guards to insn.h to prevent repeating declaration of > any identifiers in insn.h. > > Fixes: edde5584c7ab ("riscv: Add SW single-step support for KDB") > Signed-off-by: Liao Chang <liaochang1@huawei.com> > --- > arch/riscv/include/asm/insn.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h > index 25ef9c0b19e7..22c7613bfda3 100644 > --- a/arch/riscv/include/asm/insn.h > +++ b/arch/riscv/include/asm/insn.h > @@ -3,6 +3,9 @@ > * Copyright (C) 2020 SiFive > */ > > +#ifndef _ASM_RISCV_INSN_H > +#define _ASM_RISCV_INSN_H > + > #include <linux/bits.h> > > #define RV_INSN_FUNCT3_MASK GENMASK(14, 12) > @@ -365,3 +368,4 @@ static inline void riscv_insn_insert_utype_itype_imm(u32 *utype_insn, u32 *itype > *utype_insn |= (imm & RV_U_IMM_31_12_MASK) + ((imm & BIT(11)) << 1); > *itype_insn |= ((imm & RV_I_IMM_11_0_MASK) << RV_I_IMM_11_0_OPOFF); > } > +#endif /* _ASM_RISCV_INSN_H */ > -- > 2.25.1 > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Hey! On Sun, Jan 29, 2023 at 05:42:42PM +0800, Liao Chang wrote: > Add header include guards to insn.h to prevent repeating declaration of > any identifiers in insn.h. I'm curious, did you spot this "by hand" while doing other work, or do you have a tool that found it for you? > Fixes: edde5584c7ab ("riscv: Add SW single-step support for KDB") Heh, I appreciate you going back to the file's original name to find the correct fixes tag! I figure that it's probably worth adding a fixes tag for the rename too, so that the stable bots don't get confused? That would be: Fixes: c9c1af3f186a ("RISC-V: rename parse_asm.h to insn.h") Probably overkill when you have Drew's already for something so trivial, but: Reviewed-by: Conor Dooley <conor.dooley@microchip.com> > Signed-off-by: Liao Chang <liaochang1@huawei.com> > --- > arch/riscv/include/asm/insn.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h > index 25ef9c0b19e7..22c7613bfda3 100644 > --- a/arch/riscv/include/asm/insn.h > +++ b/arch/riscv/include/asm/insn.h > @@ -3,6 +3,9 @@ > * Copyright (C) 2020 SiFive > */ > > +#ifndef _ASM_RISCV_INSN_H > +#define _ASM_RISCV_INSN_H > + > #include <linux/bits.h> > > #define RV_INSN_FUNCT3_MASK GENMASK(14, 12) > @@ -365,3 +368,4 @@ static inline void riscv_insn_insert_utype_itype_imm(u32 *utype_insn, u32 *itype > *utype_insn |= (imm & RV_U_IMM_31_12_MASK) + ((imm & BIT(11)) << 1); > *itype_insn |= ((imm & RV_I_IMM_11_0_MASK) << RV_I_IMM_11_0_OPOFF); > } > +#endif /* _ASM_RISCV_INSN_H */ > -- > 2.25.1 > >
Hi, Conor 在 2023/1/30 22:53, Conor Dooley 写道: > Hey! > > On Sun, Jan 29, 2023 at 05:42:42PM +0800, Liao Chang wrote: >> Add header include guards to insn.h to prevent repeating declaration of >> any identifiers in insn.h. > > I'm curious, did you spot this "by hand" while doing other work, or do > you have a tool that found it for you? I found this "by hand", inspired by scripts/checkdeclares.pl, i write a tiny tool to analyse the missing header guards in header file. #!/usr/bin/env perl use strict; sub usage { print "Usage: checkguards.pl file1.h ...\n"; print "Warn of missing header guards\n"; exit 1; } if ($#ARGV < 0) { usage(); } foreach my $file (@ARGV) { open(my $f, '<', $file) or die "Cannot open $file: $!.\n"; my $scan_area = 1; my $guards_warn = 0; # The lines of header file are divided into several areas as follows: # # ... area1 ... # #ifndef _HEADER_GUARD # ... area2 ... # #define _HEADER_GUARD # ... area3 ... # #endif /* _HEADER_GUARD */ # ... area4 ... # EOF # # If any statement is found in area1, area2, and area4, it # throws a warning of illegal usage of header guard usage. while (<$f>) { if (m/^(.*);\s*$/o) { if ($scan_area == 1 || $scan_area == 2 || $scan_area == 4) { ++$guards_warn; } } elsif (m/^\s*(#ifndef\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { ++$scan_area; } elsif (m/^\s*(#define\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { ++$scan_area; } elsif (m/^\s*(#endif)\s*\/\*\s*[a-zA-Z0-9_]*_H[_]*\s*\*\/\s*$/o) { ++$scan_area; } } close($f); if ($guards_warn) { print "Illegal usage of header guard found in $file.\n"; } } Thanks. > >> Fixes: edde5584c7ab ("riscv: Add SW single-step support for KDB") > > Heh, I appreciate you going back to the file's original name to find the > correct fixes tag! > I figure that it's probably worth adding a fixes tag for the rename too, > so that the stable bots don't get confused? That would be: > Fixes: c9c1af3f186a ("RISC-V: rename parse_asm.h to insn.h") > > Probably overkill when you have Drew's already for something so trivial, > but: > Reviewed-by: Conor Dooley <conor.dooley@microchip.com> > >> Signed-off-by: Liao Chang <liaochang1@huawei.com> >> --- >> arch/riscv/include/asm/insn.h | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h >> index 25ef9c0b19e7..22c7613bfda3 100644 >> --- a/arch/riscv/include/asm/insn.h >> +++ b/arch/riscv/include/asm/insn.h >> @@ -3,6 +3,9 @@ >> * Copyright (C) 2020 SiFive >> */ >> >> +#ifndef _ASM_RISCV_INSN_H >> +#define _ASM_RISCV_INSN_H >> + >> #include <linux/bits.h> >> >> #define RV_INSN_FUNCT3_MASK GENMASK(14, 12) >> @@ -365,3 +368,4 @@ static inline void riscv_insn_insert_utype_itype_imm(u32 *utype_insn, u32 *itype >> *utype_insn |= (imm & RV_U_IMM_31_12_MASK) + ((imm & BIT(11)) << 1); >> *itype_insn |= ((imm & RV_I_IMM_11_0_MASK) << RV_I_IMM_11_0_OPOFF); >> } >> +#endif /* _ASM_RISCV_INSN_H */ >> -- >> 2.25.1 >> >>
Hi, On Wed, Feb 01, 2023 at 05:37:24PM +0800, liaochang (A) wrote: > 在 2023/1/30 22:53, Conor Dooley 写道: > > On Sun, Jan 29, 2023 at 05:42:42PM +0800, Liao Chang wrote: > >> Add header include guards to insn.h to prevent repeating declaration of > >> any identifiers in insn.h. > > > > I'm curious, did you spot this "by hand" while doing other work, or do > > you have a tool that found it for you? > > I found this "by hand", inspired by scripts/checkdeclares.pl, i write a tiny tool > to analyse the missing header guards in header file. Ohh, cool! I'd love to add this one to the checks on patchwork so that we do not end up adding any more of these. If this is based on checkdeclares, is it GPLv2? Thanks! > > #!/usr/bin/env perl > use strict; > > sub usage { > print "Usage: checkguards.pl file1.h ...\n"; > print "Warn of missing header guards\n"; > exit 1; > } > > if ($#ARGV < 0) { > usage(); > } > > foreach my $file (@ARGV) { > open(my $f, '<', $file) > or die "Cannot open $file: $!.\n"; > > my $scan_area = 1; > my $guards_warn = 0; > > # The lines of header file are divided into several areas as follows: > # > # ... area1 ... > # #ifndef _HEADER_GUARD > # ... area2 ... > # #define _HEADER_GUARD > # ... area3 ... > # #endif /* _HEADER_GUARD */ > # ... area4 ... > # EOF > # > # If any statement is found in area1, area2, and area4, it > # throws a warning of illegal usage of header guard usage. > while (<$f>) { > if (m/^(.*);\s*$/o) { > if ($scan_area == 1 || $scan_area == 2 || $scan_area == 4) { > ++$guards_warn; > } > } elsif (m/^\s*(#ifndef\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { > ++$scan_area; > } elsif (m/^\s*(#define\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { > ++$scan_area; > } elsif (m/^\s*(#endif)\s*\/\*\s*[a-zA-Z0-9_]*_H[_]*\s*\*\/\s*$/o) { > ++$scan_area; > } > } > > close($f); > > if ($guards_warn) { > print "Illegal usage of header guard found in $file.\n"; > } > } > > Thanks. > > > > >> Fixes: edde5584c7ab ("riscv: Add SW single-step support for KDB") > > > > Heh, I appreciate you going back to the file's original name to find the > > correct fixes tag! > > I figure that it's probably worth adding a fixes tag for the rename too, > > so that the stable bots don't get confused? That would be: > > Fixes: c9c1af3f186a ("RISC-V: rename parse_asm.h to insn.h") > > > > Probably overkill when you have Drew's already for something so trivial, > > but: > > Reviewed-by: Conor Dooley <conor.dooley@microchip.com> > > > >> Signed-off-by: Liao Chang <liaochang1@huawei.com> > >> --- > >> arch/riscv/include/asm/insn.h | 4 ++++ > >> 1 file changed, 4 insertions(+) > >> > >> diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h > >> index 25ef9c0b19e7..22c7613bfda3 100644 > >> --- a/arch/riscv/include/asm/insn.h > >> +++ b/arch/riscv/include/asm/insn.h > >> @@ -3,6 +3,9 @@ > >> * Copyright (C) 2020 SiFive > >> */ > >> > >> +#ifndef _ASM_RISCV_INSN_H > >> +#define _ASM_RISCV_INSN_H > >> + > >> #include <linux/bits.h> > >> > >> #define RV_INSN_FUNCT3_MASK GENMASK(14, 12) > >> @@ -365,3 +368,4 @@ static inline void riscv_insn_insert_utype_itype_imm(u32 *utype_insn, u32 *itype > >> *utype_insn |= (imm & RV_U_IMM_31_12_MASK) + ((imm & BIT(11)) << 1); > >> *itype_insn |= ((imm & RV_I_IMM_11_0_MASK) << RV_I_IMM_11_0_OPOFF); > >> } > >> +#endif /* _ASM_RISCV_INSN_H */ > >> -- > >> 2.25.1 > >> > >> > > -- > BR, > Liao, Chang >
在 2023/2/1 17:42, Conor Dooley 写道: > Hi, > > On Wed, Feb 01, 2023 at 05:37:24PM +0800, liaochang (A) wrote: >> 在 2023/1/30 22:53, Conor Dooley 写道: >>> On Sun, Jan 29, 2023 at 05:42:42PM +0800, Liao Chang wrote: >>>> Add header include guards to insn.h to prevent repeating declaration of >>>> any identifiers in insn.h. >>> >>> I'm curious, did you spot this "by hand" while doing other work, or do >>> you have a tool that found it for you? >> >> I found this "by hand", inspired by scripts/checkdeclares.pl, i write a tiny tool >> to analyse the missing header guards in header file. > > Ohh, cool! I'd love to add this one to the checks on patchwork so that > we do not end up adding any more of these. If this is based on > checkdeclares, is it GPLv2? Definitely, it is GPLv2,i will appending licence identifier and copyright info later. Hi,@Joe Perches, is it ok to integrate this tool to scripts? Thanks. > > Thanks! > >> >> #!/usr/bin/env perl >> use strict; >> >> sub usage { >> print "Usage: checkguards.pl file1.h ...\n"; >> print "Warn of missing header guards\n"; >> exit 1; >> } >> >> if ($#ARGV < 0) { >> usage(); >> } >> >> foreach my $file (@ARGV) { >> open(my $f, '<', $file) >> or die "Cannot open $file: $!.\n"; >> >> my $scan_area = 1; >> my $guards_warn = 0; >> >> # The lines of header file are divided into several areas as follows: >> # >> # ... area1 ... >> # #ifndef _HEADER_GUARD >> # ... area2 ... >> # #define _HEADER_GUARD >> # ... area3 ... >> # #endif /* _HEADER_GUARD */ >> # ... area4 ... >> # EOF >> # >> # If any statement is found in area1, area2, and area4, it >> # throws a warning of illegal usage of header guard usage. >> while (<$f>) { >> if (m/^(.*);\s*$/o) { >> if ($scan_area == 1 || $scan_area == 2 || $scan_area == 4) { >> ++$guards_warn; >> } >> } elsif (m/^\s*(#ifndef\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { >> ++$scan_area; >> } elsif (m/^\s*(#define\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { >> ++$scan_area; >> } elsif (m/^\s*(#endif)\s*\/\*\s*[a-zA-Z0-9_]*_H[_]*\s*\*\/\s*$/o) { >> ++$scan_area; >> } >> } >> >> close($f); >> >> if ($guards_warn) { >> print "Illegal usage of header guard found in $file.\n"; >> } >> } >> >> Thanks. >> >>> >>>> Fixes: edde5584c7ab ("riscv: Add SW single-step support for KDB") >>> >>> Heh, I appreciate you going back to the file's original name to find the >>> correct fixes tag! >>> I figure that it's probably worth adding a fixes tag for the rename too, >>> so that the stable bots don't get confused? That would be: >>> Fixes: c9c1af3f186a ("RISC-V: rename parse_asm.h to insn.h") >>> >>> Probably overkill when you have Drew's already for something so trivial, >>> but: >>> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> >>> >>>> Signed-off-by: Liao Chang <liaochang1@huawei.com> >>>> --- >>>> arch/riscv/include/asm/insn.h | 4 ++++ >>>> 1 file changed, 4 insertions(+) >>>> >>>> diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h >>>> index 25ef9c0b19e7..22c7613bfda3 100644 >>>> --- a/arch/riscv/include/asm/insn.h >>>> +++ b/arch/riscv/include/asm/insn.h >>>> @@ -3,6 +3,9 @@ >>>> * Copyright (C) 2020 SiFive >>>> */ >>>> >>>> +#ifndef _ASM_RISCV_INSN_H >>>> +#define _ASM_RISCV_INSN_H >>>> + >>>> #include <linux/bits.h> >>>> >>>> #define RV_INSN_FUNCT3_MASK GENMASK(14, 12) >>>> @@ -365,3 +368,4 @@ static inline void riscv_insn_insert_utype_itype_imm(u32 *utype_insn, u32 *itype >>>> *utype_insn |= (imm & RV_U_IMM_31_12_MASK) + ((imm & BIT(11)) << 1); >>>> *itype_insn |= ((imm & RV_I_IMM_11_0_MASK) << RV_I_IMM_11_0_OPOFF); >>>> } >>>> +#endif /* _ASM_RISCV_INSN_H */ >>>> -- >>>> 2.25.1 >>>> >>>> >> >> -- >> BR, >> Liao, Chang >>
On Thu, 2023-02-02 at 08:52 +0800, liaochang (A) wrote: > > 在 2023/2/1 17:42, Conor Dooley 写道: > > Hi, > > > > On Wed, Feb 01, 2023 at 05:37:24PM +0800, liaochang (A) wrote: > > > 在 2023/1/30 22:53, Conor Dooley 写道: > > > > On Sun, Jan 29, 2023 at 05:42:42PM +0800, Liao Chang wrote: > > > > > Add header include guards to insn.h to prevent repeating declaration of > > > > > any identifiers in insn.h. > > > > > > > > I'm curious, did you spot this "by hand" while doing other work, or do > > > > you have a tool that found it for you? > > > > > > I found this "by hand", inspired by scripts/checkdeclares.pl, i write a tiny tool > > > to analyse the missing header guards in header file. > > > > Ohh, cool! I'd love to add this one to the checks on patchwork so that > > we do not end up adding any more of these. If this is based on > > checkdeclares, is it GPLv2? > > Definitely, it is GPLv2,i will appending licence identifier and copyright info later. > > Hi,@Joe Perches, is it ok to integrate this tool to scripts? Don't see why not. Perhaps submit it as a real patch to Andrew Morton <akpm@linux-foundation.org> Trivial notes below: > > > #!/usr/bin/env perl > > > use strict; > > > > > > sub usage { > > > print "Usage: checkguards.pl file1.h ...\n"; > > > print "Warn of missing header guards\n"; > > > exit 1; > > > } > > > > > > if ($#ARGV < 0) { > > > usage(); > > > } > > > > > > foreach my $file (@ARGV) { > > > open(my $f, '<', $file) > > > or die "Cannot open $file: $!.\n"; > > > > > > my $scan_area = 1; > > > my $guards_warn = 0; > > > > > > # The lines of header file are divided into several areas as follows: > > > # > > > # ... area1 ... > > > # #ifndef _HEADER_GUARD > > > # ... area2 ... > > > # #define _HEADER_GUARD > > > # ... area3 ... > > > # #endif /* _HEADER_GUARD */ > > > # ... area4 ... > > > # EOF > > > # > > > # If any statement is found in area1, area2, and area4, it > > > # throws a warning of illegal usage of header guard usage. Not illegal, invalid > > > while (<$f>) { > > > if (m/^(.*);\s*$/o) { > > > if ($scan_area == 1 || $scan_area == 2 || $scan_area == 4) { > > > ++$guards_warn; > > > } > > > } elsif (m/^\s*(#ifndef\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { > > > ++$scan_area; > > > } elsif (m/^\s*(#define\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { > > > ++$scan_area; > > > } elsif (m/^\s*(#endif)\s*\/\*\s*[a-zA-Z0-9_]*_H[_]*\s*\*\/\s*$/o) { > > > ++$scan_area; > > > } > > > } > > > > > > close($f); > > > > > > if ($guards_warn) { > > > print "Illegal usage of header guard found in $file.\n"; here too There are also uses like #if !defined(FOO) There can be spaces before and after the # It might also be useful to have a check for missing header guards.
在 2023/2/2 11:33, Joe Perches 写道: > On Thu, 2023-02-02 at 08:52 +0800, liaochang (A) wrote: >> >> 在 2023/2/1 17:42, Conor Dooley 写道: >>> Hi, >>> >>> On Wed, Feb 01, 2023 at 05:37:24PM +0800, liaochang (A) wrote: >>>> 在 2023/1/30 22:53, Conor Dooley 写道: >>>>> On Sun, Jan 29, 2023 at 05:42:42PM +0800, Liao Chang wrote: >>>>>> Add header include guards to insn.h to prevent repeating declaration of >>>>>> any identifiers in insn.h. >>>>> >>>>> I'm curious, did you spot this "by hand" while doing other work, or do >>>>> you have a tool that found it for you? >>>> >>>> I found this "by hand", inspired by scripts/checkdeclares.pl, i write a tiny tool >>>> to analyse the missing header guards in header file. >>> >>> Ohh, cool! I'd love to add this one to the checks on patchwork so that >>> we do not end up adding any more of these. If this is based on >>> checkdeclares, is it GPLv2? >> >> Definitely, it is GPLv2,i will appending licence identifier and copyright info later. >> >> Hi,@Joe Perches, is it ok to integrate this tool to scripts? > > Don't see why not. > Perhaps submit it as a real patch to Andrew Morton <akpm@linux-foundation.org> > > Trivial notes below: > >>>> #!/usr/bin/env perl >>>> use strict; >>>> >>>> sub usage { >>>> print "Usage: checkguards.pl file1.h ...\n"; >>>> print "Warn of missing header guards\n"; >>>> exit 1; >>>> } >>>> >>>> if ($#ARGV < 0) { >>>> usage(); >>>> } >>>> >>>> foreach my $file (@ARGV) { >>>> open(my $f, '<', $file) >>>> or die "Cannot open $file: $!.\n"; >>>> >>>> my $scan_area = 1; >>>> my $guards_warn = 0; >>>> >>>> # The lines of header file are divided into several areas as follows: >>>> # >>>> # ... area1 ... >>>> # #ifndef _HEADER_GUARD >>>> # ... area2 ... >>>> # #define _HEADER_GUARD >>>> # ... area3 ... >>>> # #endif /* _HEADER_GUARD */ >>>> # ... area4 ... >>>> # EOF >>>> # >>>> # If any statement is found in area1, area2, and area4, it >>>> # throws a warning of illegal usage of header guard usage. > > Not illegal, invalid > >>>> while (<$f>) { >>>> if (m/^(.*);\s*$/o) { >>>> if ($scan_area == 1 || $scan_area == 2 || $scan_area == 4) { >>>> ++$guards_warn; >>>> } >>>> } elsif (m/^\s*(#ifndef\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { >>>> ++$scan_area; >>>> } elsif (m/^\s*(#define\s+)[a-zA-Z0-9_]*_H[_]*\s*$/o) { >>>> ++$scan_area; >>>> } elsif (m/^\s*(#endif)\s*\/\*\s*[a-zA-Z0-9_]*_H[_]*\s*\*\/\s*$/o) { >>>> ++$scan_area; >>>> } >>>> } >>>> >>>> close($f); >>>> >>>> if ($guards_warn) { >>>> print "Illegal usage of header guard found in $file.\n"; > > here too > > There are also uses like #if !defined(FOO) > There can be spaces before and after the # > > It might also be useful to have a check for missing header guards. OK, i will use a stricter pattern in the real patch. Thanks. > > > >
Hello: This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <palmer@rivosinc.com>: On Sun, 29 Jan 2023 17:42:42 +0800 you wrote: > Add header include guards to insn.h to prevent repeating declaration of > any identifiers in insn.h. > > Fixes: edde5584c7ab ("riscv: Add SW single-step support for KDB") > Signed-off-by: Liao Chang <liaochang1@huawei.com> > --- > arch/riscv/include/asm/insn.h | 4 ++++ > 1 file changed, 4 insertions(+) Here is the summary with links: - riscv: Add header include guards to insn.h https://git.kernel.org/riscv/c/8ac6e619d9d5 You are awesome, thank you!
diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h index 25ef9c0b19e7..22c7613bfda3 100644 --- a/arch/riscv/include/asm/insn.h +++ b/arch/riscv/include/asm/insn.h @@ -3,6 +3,9 @@ * Copyright (C) 2020 SiFive */ +#ifndef _ASM_RISCV_INSN_H +#define _ASM_RISCV_INSN_H + #include <linux/bits.h> #define RV_INSN_FUNCT3_MASK GENMASK(14, 12) @@ -365,3 +368,4 @@ static inline void riscv_insn_insert_utype_itype_imm(u32 *utype_insn, u32 *itype *utype_insn |= (imm & RV_U_IMM_31_12_MASK) + ((imm & BIT(11)) << 1); *itype_insn |= ((imm & RV_I_IMM_11_0_MASK) << RV_I_IMM_11_0_OPOFF); } +#endif /* _ASM_RISCV_INSN_H */