diff mbox series

checkpatch: warn when using volatile with a comment

Message ID 20171215181810.4122-1-marcandre.lureau@redhat.com
State New
Headers show
Series checkpatch: warn when using volatile with a comment | expand

Commit Message

Marc-André Lureau Dec. 15, 2017, 6:18 p.m. UTC
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"'

Suggested-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/checkpatch.pl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

no-reply@patchew.org Dec. 15, 2017, 6:39 p.m. UTC | #1
Hi,

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

Type: series
Message-id: 20171215181810.4122-1-marcandre.lureau@redhat.com
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/20171215150659.1811-1-marcandre.lureau@redhat.com -> patchew/20171215150659.1811-1-marcandre.lureau@redhat.com
 t [tag update]            patchew/20171215181810.4122-1-marcandre.lureau@redhat.com -> patchew/20171215181810.4122-1-marcandre.lureau@redhat.com
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 patchew-devel@freelists.org
Paolo Bonzini Dec. 18, 2017, 12:49 p.m. UTC | #2
On 15/12/2017 19:18, Marc-André Lureau wrote:
> 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"'
> 
> Suggested-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

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:

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f5a523af10..3dc27d9656 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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
Marc-André Lureau Dec. 18, 2017, 12:54 p.m. UTC | #3
Hi

On Mon, Dec 18, 2017 at 1:49 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 15/12/2017 19:18, Marc-André Lureau wrote:
>> 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"'
>>
>> Suggested-by: Fam Zheng <famz@redhat.com>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> 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:
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index f5a523af10..3dc27d9656 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -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);
>                 }
>

Fine for me, can you send a proper patch?

Thanks
Paolo Bonzini Dec. 18, 2017, 1:02 p.m. UTC | #4
On 18/12/2017 13:54, Marc-André Lureau wrote:
> Hi
> 
> On Mon, Dec 18, 2017 at 1:49 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> On 15/12/2017 19:18, Marc-André Lureau wrote:
>>> 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"'
>>>
>>> Suggested-by: Fam Zheng <famz@redhat.com>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>
>> 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:
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index f5a523af10..3dc27d9656 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -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);
>>                 }
>>
> 
> Fine for me, can you send a proper patch?

Yes, will do.

Paolo
Darren Kenny Dec. 18, 2017, 1:36 p.m. UTC | #5
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.

On Mon, Dec 18, 2017 at 01:49:52PM +0100, Paolo Bonzini wrote:
>On 15/12/2017 19:18, Marc-André Lureau wrote:
>> 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"'
>>
>> Suggested-by: Fam Zheng <famz@redhat.com>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
>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:
>
>diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>index f5a523af10..3dc27d9656 100755
>--- a/scripts/checkpatch.pl
>+++ b/scripts/checkpatch.pl
>@@ -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
>
Darren Kenny Dec. 18, 2017, 1:38 p.m. UTC | #6
Nevermind, saw that updated comment in the later patch...

Thanks,

Darren.

On Mon, Dec 18, 2017 at 01:36:52PM +0000, Darren Kenny wrote:
>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.
>
>On Mon, Dec 18, 2017 at 01:49:52PM +0100, Paolo Bonzini wrote:
>>On 15/12/2017 19:18, Marc-André Lureau wrote:
>>>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"'
>>>
>>>Suggested-by: Fam Zheng <famz@redhat.com>
>>>Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>
>>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:
>>
>>diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>>index f5a523af10..3dc27d9656 100755
>>--- a/scripts/checkpatch.pl
>>+++ b/scripts/checkpatch.pl
>>@@ -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
>>
diff mbox series

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 34df753571..f5a523af10 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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