Skip to contentSkip to conversation

checkpatch: Do not warn __initconst for const char *.

PATCH New Masami Hiramatsu 1 participant 1 message Aug 26, 2021 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: Do not warn __initconst for const char *.

checkpatch.pl warns if an '__initdata' variable has 'const' attribute to use __initconst, but it doesn't check that attribute affects the type of a pointer or the variable. Thus it reports an false error if 'const char *' variable is '__initdata'. e.g.

ERROR: Use of const init definition must use __initconst #32: FILE: lib/bootconfig.c:32:
+static const char *xbc_err_msg __initdata;

To fix this issue, this ensures that the 'const' does not follows any type string and a pointer ('*') too.

---
 scripts/checkpatch.pl |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 461d4221e4a4..c04213a7b633 100755
@@ -6330,7 +6330,7 @@ sub process {
 		}
 
 # check for $InitAttributeData (ie: __initdata) with const
-		if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
+		if ($line =~ /\bconst\b/ && $line !~ /\bconst\b[^\*\(]+\*/ && $line =~ /($InitAttributeData)/) {
 			my $attr = $1;
 			$attr =~ /($InitAttributePrefix)(.*)/;
 			my $attr_prefix = $1;