Skip to contentSkip to conversation

checkpatch: warn when using volatile with a comment

PATCH In review Marc-André Lureau 5 participants 7 messages Dec 15, 2017 – Dec 18, 2017 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: warn when using volatile with a comment

Instead of an error, lower to a warning message, assuming the comment gives some justification.

Discussed in:
'[Qemu-devel] [PATCH] dump-guest-memory.py: fix "You can't do that without a process to debug"'

---
 scripts/checkpatch.pl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +6 -1
index 34df753571..f5a523af10 100755
@@ -2476,7 +2476,12 @@ sub process {
 # no volatiles please
 		my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
 		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
-			ERROR("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
+			my $msg = "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr;
+			if (ctx_has_comment($first_line, $linenr)) {
+				WARN($msg);
+			} else {
+				ERROR($msg);
+			}
 		}
 
 # warn about #if 0
Signature · 1 line
2.15.1.355.g36791d7216
#1 lore raw
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] checkpatch: warn when using volatile with a comment

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
t [tag update] patchew/[email protected] -> patchew/[email protected]
t [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
80828ed1b5 checkpatch: warn when using volatile with a comment

=== OUTPUT BEGIN ===
Checking PATCH 1/1: checkpatch: warn when using volatile with a comment...
ERROR: line over 90 characters
#28: FILE: scripts/checkpatch.pl:2479:
+ my $msg = "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr;

total: 1 errors, 0 warnings, 13 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
In reply to Marc-André Lureau
Quoted 8 lines · Marc-André Lureau

Instead of an error, lower to a warning message, assuming the comment gives some justification.

Discussed in:
'[Qemu-devel] [PATCH] dump-guest-memory.py: fix "You can't do that without a process to debug"'

We can drop the error at all if there is a comment. Also, "volatile sig_atomic_t" is probably self-explanatory and usually correct. So what about this:

scripts/checkpatch.pl +5 -7
index f5a523af10..3dc27d9656 100755
@@ -2475,13 +2475,11 @@ sub process {
 
 # no volatiles please
 		my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
-		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
-			my $msg = "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr;
-			if (ctx_has_comment($first_line, $linenr)) {
-				WARN($msg);
-			} else {
-				ERROR($msg);
-			}
+		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/ &&
+                    $line !~ /sig_atomic_t/ &&
+                    !ctx_has_comment($first_line, $linenr)) {
+			my $msg = "Use of volatile is usually wrong, please add a comment\n" . $herecurr;
+                        ERROR($msg);
 		}
 
 # warn about #if 0
#3 lore raw

Hi

Quoted 24 lines · Paolo Bonzini
Quoted 8 lines · Marc-André Lureau

Instead of an error, lower to a warning message, assuming the comment gives some justification.

Discussed in:
'[Qemu-devel] [PATCH] dump-guest-memory.py: fix "You can't do that without a process to debug"'

We can drop the error at all if there is a comment. Also, "volatile sig_atomic_t" is probably self-explanatory and usually correct. So what about this:

scripts/checkpatch.pl +0 -4
index f5a523af10..3dc27d9656 100755
@@ -2475,13 +2475,11 @@ sub process {
 
 # no volatiles please
                my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
-               if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
-                       my $msg = "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr;
-                       if (ctx_has_comment($first_line, $linenr)) {
-                               WARN($msg);

scripts/checkpatch.pl sub process { · line 2484

Quoted 10 lines
scripts/checkpatch.pl +5 -3
-                       } else {
-                               ERROR($msg);
-                       }
+               if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/ &&
+                    $line !~ /sig_atomic_t/ &&
+                    !ctx_has_comment($first_line, $linenr)) {
+                       my $msg = "Use of volatile is usually wrong, please add a comment\n" . $herecurr;
+                        ERROR($msg);
                }
 

Fine for me, can you send a proper patch?

Thanks

Signature · 1 line
Marc-André Lureau
#4 lore raw
Quoted 31 lines · Marc-André Lureau

Hi

Quoted 28 lines · Paolo Bonzini
Quoted 8 lines · Marc-André Lureau

Instead of an error, lower to a warning message, assuming the comment gives some justification.

Discussed in:
'[Qemu-devel] [PATCH] dump-guest-memory.py: fix "You can't do that without a process to debug"'

We can drop the error at all if there is a comment. Also, "volatile sig_atomic_t" is probably self-explanatory and usually correct. So what about this:

scripts/checkpatch.pl +1 -7
index f5a523af10..3dc27d9656 100755
@@ -2475,13 +2475,11 @@ sub process {
 
 # no volatiles please
                my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
-               if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
-                       my $msg = "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr;
-                       if (ctx_has_comment($first_line, $linenr)) {
-                               WARN($msg);
-                       } else {
-                               ERROR($msg);
-                       }
+               if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/ &&
Quoted 8 lines

scripts/checkpatch.pl sub process { · line 2484

Quoted 6 lines
scripts/checkpatch.pl +4 -0
+                    $line !~ /sig_atomic_t/ &&
+                    !ctx_has_comment($first_line, $linenr)) {
+                       my $msg = "Use of volatile is usually wrong, please add a comment\n" . $herecurr;
+                        ERROR($msg);
                }
 

Fine for me, can you send a proper patch?

Yes, will do.

Paolo

#5 lore raw
In reply to Paolo Bonzini

Hi Paolo,

Slight nit on the subject line, did you mean to s/with/without/ - that seems to reflect the change in the patch more correctly.

Thanks,

Darren.

Quoted 36 lines · Paolo Bonzini
Quoted 8 lines · Marc-André Lureau

Instead of an error, lower to a warning message, assuming the comment gives some justification.

Discussed in:
'[Qemu-devel] [PATCH] dump-guest-memory.py: fix "You can't do that without a process to debug"'

We can drop the error at all if there is a comment. Also, "volatile sig_atomic_t" is probably self-explanatory and usually correct. So what about this:

scripts/checkpatch.pl +5 -7
index f5a523af10..3dc27d9656 100755
@@ -2475,13 +2475,11 @@ sub process {
 
 # no volatiles please
 		my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
-		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
-			my $msg = "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr;
-			if (ctx_has_comment($first_line, $linenr)) {
-				WARN($msg);
-			} else {
-				ERROR($msg);
-			}
+		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/ &&
+                    $line !~ /sig_atomic_t/ &&
+                    !ctx_has_comment($first_line, $linenr)) {
+			my $msg = "Use of volatile is usually wrong, please add a comment\n" . $herecurr;
+                        ERROR($msg);
 		}
 
 # warn about #if 0
#6 lore raw

Nevermind, saw that updated comment in the later patch...

Thanks,

Darren.

Quoted 46 lines · Darren Kenny

Hi Paolo,

Slight nit on the subject line, did you mean to s/with/without/ - that seems to reflect the change in the patch more correctly.

Thanks,

Darren.

Quoted 36 lines · Paolo Bonzini
Quoted 8 lines · Marc-André Lureau

Instead of an error, lower to a warning message, assuming the comment gives some justification.

Discussed in:
'[Qemu-devel] [PATCH] dump-guest-memory.py: fix "You can't do that without a process to debug"'

We can drop the error at all if there is a comment. Also, "volatile sig_atomic_t" is probably self-explanatory and usually correct. So what about this:

scripts/checkpatch.pl +5 -7
index f5a523af10..3dc27d9656 100755
@@ -2475,13 +2475,11 @@ sub process {
 
 # no volatiles please
 		my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
-		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
-			my $msg = "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr;
-			if (ctx_has_comment($first_line, $linenr)) {
-				WARN($msg);
-			} else {
-				ERROR($msg);
-			}
+		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/ &&
+                    $line !~ /sig_atomic_t/ &&
+                    !ctx_has_comment($first_line, $linenr)) {
+			my $msg = "Use of volatile is usually wrong, please add a comment\n" . $herecurr;
+                        ERROR($msg);
 		}
 
 # warn about #if 0