[PATCH] checkpatch: Ignore attribute macros ending with nGnRnE or nGnRE

Liu Dalin posted 1 patch 1 month ago
scripts/checkpatch.pl | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] checkpatch: Ignore attribute macros ending with nGnRnE or nGnRE
Posted by Liu Dalin 1 month ago
On arm and arm64 platforms, there are several attribute macros that
end with nGnRnE or nGnRE, such as PROT_DEVICE_nGnRnE, PROT_DEVICE_nGnRE,
MT_DEVICE_nGnRnE, and MT_DEVICE_nGnRE.

Signed-off-by: Liu Dalin <liudalin@kylinsec.com.cn>
---
 scripts/checkpatch.pl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e56374662ff7..f5b5d72cb069 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5896,7 +5896,10 @@ sub process {
 #(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE)
 			    $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
 #Ignore some three character SI units explicitly, like MiB and KHz
-			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
+			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/ &&
+#Ignore macros end with nGnRnE or nGnRE
+#(ie: PROT_DEVICE_<foo>, MT_DEVICE_<foo> MT_S2_DEVICE_<foo> ...)
+			    $var !~ /^[A-Z0-9_]+_(nGnRnE|nGnRE)$/) {
 				while ($var =~ m{\b($Ident)}g) {
 					my $word = $1;
 					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
-- 
2.43.0
[PATCH 0/1] checkpatch: ignore memory attribute macros ending with nGnRnE, nGnRE, or nGRE
Posted by Liu Dalin 1 month ago
Changes in v2:
- add nGRE and using (?:...)$
- update commit tile and info

Liu Dalin (1):
  checkpatch: ignore memory attribute macros ending with nGnRnE, nGnRE,
    or nGRE

 scripts/checkpatch.pl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

-- 
2.43.0
Re: [PATCH] checkpatch: Ignore attribute macros ending with nGnRnE or nGnRE
Posted by Joe Perches 1 month ago
On Sat, 2026-03-07 at 15:27 +0800, Liu Dalin wrote:
> On arm and arm64 platforms, there are several attribute macros that
> end with nGnRnE or nGnRE, such as PROT_DEVICE_nGnRnE, PROT_DEVICE_nGnRE,
> MT_DEVICE_nGnRnE, and MT_DEVICE_nGnRE.

+			    $var !~ /^[A-Z0-9_]+_(nGnRnE|nGnRE)$/) {

Maybe better if you add nGRE too and no capture group using (?:...)$

FYI: These appear unused to date:

$ git grep FFA_DEV
include/linux/arm_ffa.h:#define FFA_DEV_nGnRnE          (0 << 2)
include/linux/arm_ffa.h:#define FFA_DEV_nGnRE           (1 << 2)
include/linux/arm_ffa.h:#define FFA_DEV_nGRE            (2 << 2)
include/linux/arm_ffa.h:#define FFA_DEV_GRE             (3 << 2)
Re: [PATCH] checkpatch: Ignore attribute macros ending with nGnRnE or nGnRE
Posted by Liu Dalin 1 month ago
Thanks for the review!

在 2026/3/8 3:53, Joe Perches 写道:
> On Sat, 2026-03-07 at 15:27 +0800, Liu Dalin wrote:
>> On arm and arm64 platforms, there are several attribute macros that
>> end with nGnRnE or nGnRE, such as PROT_DEVICE_nGnRnE, PROT_DEVICE_nGnRE,
>> MT_DEVICE_nGnRnE, and MT_DEVICE_nGnRE.
> +			    $var !~ /^[A-Z0-9_]+_(nGnRnE|nGnRE)$/) {
>
> Maybe better if you add nGRE too and no capture group using (?:...)$

OK!  This is a good suggestion.

I will add it in patch v2.

> FYI: These appear unused to date:

On other ARM platforms, these memory attribute macros are used in arch, 
drivers, or KVM.

likes:

$ git grep PROT_DEVICE_nGnRnE
arch/arm64/include/asm/io.h:#define pci_remap_cfgspace(addr, size) 
__ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRnE))
arch/arm64/include/asm/pgtable-prot.h:#define PROT_DEVICE_nGnRnE       
(PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | 
PTE_ATTRINDX(MT_DEVICE_nGnRnE))
arch/arm64/kernel/acpi.c:       return __pgprot(PROT_DEVICE_nGnRnE);
drivers/net/ethernet/huawei/hinic/hinic_lld.c:                     
__pgprot(PROT_DEVICE_nGnRnE));
drivers/net/ethernet/phytium/phytmac.h:#define phytmac_ioremap_np(addr, 
size)   __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRnE))
drivers/scsi/huawei/hifc/hifc_lld.c:             
__pgprot(PROT_DEVICE_nGnRnE));

> $ git grep FFA_DEV
> include/linux/arm_ffa.h:#define FFA_DEV_nGnRnE          (0 << 2)
> include/linux/arm_ffa.h:#define FFA_DEV_nGnRE           (1 << 2)
> include/linux/arm_ffa.h:#define FFA_DEV_nGRE            (2 << 2)
> include/linux/arm_ffa.h:#define FFA_DEV_GRE             (3 << 2)
>
Re: [PATCH] checkpatch: Ignore attribute macros ending with nGnRnE or nGnRE
Posted by Joe Perches 1 month ago
On Mon, 2026-03-09 at 10:12 +0800, Liu Dalin wrote:
> 在 2026/3/8 3:53, Joe Perches 写道:

> > FYI: These appear unused to date:

[]

I was referring to these #define FFA_DEV_<foo> below:

> > $ git grep FFA_DEV
> > include/linux/arm_ffa.h:#define FFA_DEV_nGnRnE          (0 << 2)
> > include/linux/arm_ffa.h:#define FFA_DEV_nGnRE           (1 << 2)
> > include/linux/arm_ffa.h:#define FFA_DEV_nGRE            (2 << 2)
> > include/linux/arm_ffa.h:#define FFA_DEV_GRE             (3 << 2)
Re: [PATCH] checkpatch: Ignore attribute macros ending with nGnRnE or nGnRE
Posted by Liu Dalin 1 month ago
在 2026/3/9 10:47, Joe Perches 写道:
> On Mon, 2026-03-09 at 10:12 +0800, Liu Dalin wrote:
>> 在 2026/3/8 3:53, Joe Perches 写道:
>>> FYI: These appear unused to date:
> []
>
> I was referring to these #define FFA_DEV_<foo> below:
Yes.
It looks like the memory attribute macros starting with FFA_DEV_are 
intended for use in ARM Trusted Firmware​ and Hypervisors, and are 
rarely seen in the kernel​ itself.
Maybe some TEE drivers will use these attributes.
>>> $ git grep FFA_DEV
>>> include/linux/arm_ffa.h:#define FFA_DEV_nGnRnE          (0 << 2)
>>> include/linux/arm_ffa.h:#define FFA_DEV_nGnRE           (1 << 2)
>>> include/linux/arm_ffa.h:#define FFA_DEV_nGRE            (2 << 2)
>>> include/linux/arm_ffa.h:#define FFA_DEV_GRE             (3 << 2)