Skip to contentSkip to conversation

checkpatch: don't warn on every struct without const_structs file

PATCH NAK Johannes Berg 2 participants 6 messages Jan 10, 2017 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: don't warn on every struct without const_structs file

From: Johannes Berg <[email protected]>

The script says that it won't warn:
"No structs that should be const will be found [...]"

but then that doesn't work and it warns on every single struct instead, since the regular expression ends up empty. Fix that by checking that it's not empty first.

Fixes bf1fa1dae68e ("checkpatch: externalize the structs that should be const")
---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index a8368d1c4348..722a319acec5 100755
@@ -6010,7 +6010,8 @@ sub process {
 		}
 
 # check for various structs that are normally const (ops, kgdb, device_tree)
-		if ($line !~ /\bconst\b/ &&
+		if ($const_structs ne "" &&
+		    $line !~ /\bconst\b/ &&
 		    $line =~ /\bstruct\s+($const_structs)\b/) {
 			WARN("CONST_STRUCT",
 			     "struct $1 should normally be const\n" .
Signature · 1 line
2.9.3
maintainer NAK
#1 lore raw
Quoted 8 lines · Johannes Berg

From: Johannes Berg <[email protected]>

The script says that it won't warn:
"No structs that should be const will be found [...]"

but then that doesn't work and it warns on every single struct instead, since the regular expression ends up empty. Fix that by checking that it's not empty first.

nak.

How does const_structs end up empty for you?

#2 lore raw
Quoted 6 lines · Joe Perches
Quoted 5 lines · Johannes Berg

From: Johannes Berg <[email protected]>

The script says that it won't warn:
"No structs that should be const will be found [...]"

Quoted 7 lines
Quoted 3 lines

but then that doesn't work and it warns on every single struct instead, since the regular expression ends up empty. Fix that by checking that it's not empty first.

nak.

How does const_structs end up empty for you?

I copied checkpatch elsewhere and ran it.

Regardless, the current code is utterly stupid - it prints a warning that it won't flag any structs, and then proceeds to flag all structs.

If you must, send a patch to abort() [whatever the perl equivalent is] when the file can't be found, but as it is, the code is just idiotic.

johannes

maintainer
#3 lore raw
Quoted 11 lines · Johannes Berg
Quoted 10 lines · Joe Perches
Quoted 8 lines · Johannes Berg

From: Johannes Berg <[email protected]>

The script says that it won't warn:
"No structs that should be const will be found [...]"

but then that doesn't work and it warns on every single struct instead, since the regular expression ends up empty. Fix that by checking that it's not empty first.

Quoted 5 lines
Quoted 3 lines

nak.

How does const_structs end up empty for you?

I copied checkpatch elsewhere and ran it.

Why do you want to copy checkpatch "someplace else"? Instead of copy, I think you should soft link it.

Quoted 5 lines

Regardless, the current code is utterly stupid - it prints a warning that it won't flag any structs, and then proceeds to flag all structs.

If you must, send a patch to abort() [whatever the perl equivalent is] when the file can't be found, but as it is, the code is just idiotic.

Maybe so.

As is, your patch description is incomplete because it doesn't mention your use case.

#4 lore raw
Quoted 4 lines
Quoted 1 line

I copied checkpatch elsewhere and ran it.

Why do you want to copy checkpatch "someplace else"? Instead of copy, I think you should soft link it.

Well, no, I have to distribute it with that.

Quoted 4 lines
Quoted 4 lines

Regardless, the current code is utterly stupid - it prints a warning that it won't flag any structs, and then proceeds to flag all structs.

Quoted 8 lines
Quoted 3 lines

If you must, send a patch to abort() [whatever the perl equivalent is] when the file can't be found, but as it is, the code is just idiotic.

Maybe so.

As is, your patch description is incomplete because it doesn't mention your use case.

I don't think that's relevant. The script is internally inconsistent, as I do mention in the commit log, which is worth fixing.

johannes

maintainer
#5 lore raw
Quoted 15 lines · Johannes Berg
Quoted 4 lines
Quoted 1 line

I copied checkpatch elsewhere and ran it.

Why do you want to copy checkpatch "someplace else"? Instead of copy, I think you should soft link it.

Well, no, I have to distribute it with that.

Quoted 8 lines
Quoted 7 lines

Regardless, the current code is utterly stupid - it prints a warning that it won't flag any structs, and then proceeds to flag all structs.

If you must, send a patch to abort() [whatever the perl equivalent is] when the file can't be found, but as it is, the code is just idiotic.

Quoted 6 lines
Quoted 4 lines

Maybe so.

As is, your patch description is incomplete because it doesn't mention your use case.

I don't think that's relevant.

I do. checkpatch is a script written for linux patches.

You are making use of the script outside of the linux tree. You could just as well keep a local copy of this patch instead.

Your patch allows you to avoid this and the patch description is relevant to why this is useful.

So your patch description is simply incorrect/incomplete:

---------------------------------------------------------------
The script says that it won't warn:
"No structs that should be const will be found [...]"

but then that doesn't work and it warns on every single struct instead, since the regular expression ends up empty. Fix that by checking that it's not empty first.
---------------------------------------------------------------

When used for linux, checkpatch works just fine and your patch description describes a condition that doesn't happen.

Quoted 2 lines

The script is internally inconsistent,
as I do mention in the commit log, which is worth fixing.

Yeah, I think it's useful to fix.

Just make the commit message describe why the patch is appropriate for non-linux uses.