diff mbox

[PULL,7/9] checkpatch: check trace-events code style

Message ID 20170801131618.27332-8-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi Aug. 1, 2017, 1:16 p.m. UTC
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

According to CODING_STYLE, check that in trace-events:
1. hex numbers are prefixed with '0x'
2. '#' flag of printf is not used
3. The exclusion from 1. are period-separated groups of numbers

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20170731160135.12101-4-vsementsov@virtuozzo.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 scripts/checkpatch.pl | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Alex Williamson Aug. 29, 2017, 9:34 p.m. UTC | #1
On Tue,  1 Aug 2017 14:16:16 +0100
Stefan Hajnoczi <stefanha@redhat.com> wrote:

> From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> 
> According to CODING_STYLE, check that in trace-events:
> 1. hex numbers are prefixed with '0x'
> 2. '#' flag of printf is not used
> 3. The exclusion from 1. are period-separated groups of numbers
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Message-id: 20170731160135.12101-4-vsementsov@virtuozzo.com
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  scripts/checkpatch.pl | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 4e91122813..fa478074b8 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -1337,6 +1337,25 @@ sub process {
>  			$rpt_cleaners = 1;
>  		}
>  
> +# checks for trace-events files
> +		if ($realfile =~ /trace-events$/ && $line =~ /^\+/) {
> +			if ($rawline =~ /%[-+ 0]*#/) {
> +				ERROR("Don't use '#' flag of printf format ('%#') in " .
> +				      "trace-events, use '0x' prefix instead\n" . $herecurr);
> +			} else {
> +				my $hex =
> +					qr/%[-+ *.0-9]*([hljztL]|ll|hh)?(x|X|"\s*PRI[xX][^"]*"?)/;
> +
> +				# don't consider groups splitted by [.:/ ], like 2A.20:12ab
> +				my $tmpline = $rawline =~ s/($hex[.:\/ ])+$hex//gr;
> +
> +				if ($tmpline =~ /(?<!0x)$hex/) {
> +					ERROR("Hex numbers must be prefixed with '0x'\n" .
> +					      $herecurr);
> +				}
> +			}
> +		}
> +
>  # check we are in a valid source file if not then ignore this hunk
>  		next if ($realfile !~ /\.(h|c|cpp|s|S|pl|py|sh)$/);
>  

This broke checkpatch.pl for me:

Bareword found where operator expected at ./scripts/checkpatch.pl line 1350, near "s/($hex[.:\/ ])+$hex//gr"
syntax error at ./scripts/checkpatch.pl line 1350, near "s/($hex[.:\/ ])+$hex//gr"
Execution of ./scripts/checkpatch.pl aborted due to compilation errors.

$ perl -v

This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
diff mbox

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4e91122813..fa478074b8 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1337,6 +1337,25 @@  sub process {
 			$rpt_cleaners = 1;
 		}
 
+# checks for trace-events files
+		if ($realfile =~ /trace-events$/ && $line =~ /^\+/) {
+			if ($rawline =~ /%[-+ 0]*#/) {
+				ERROR("Don't use '#' flag of printf format ('%#') in " .
+				      "trace-events, use '0x' prefix instead\n" . $herecurr);
+			} else {
+				my $hex =
+					qr/%[-+ *.0-9]*([hljztL]|ll|hh)?(x|X|"\s*PRI[xX][^"]*"?)/;
+
+				# don't consider groups splitted by [.:/ ], like 2A.20:12ab
+				my $tmpline = $rawline =~ s/($hex[.:\/ ])+$hex//gr;
+
+				if ($tmpline =~ /(?<!0x)$hex/) {
+					ERROR("Hex numbers must be prefixed with '0x'\n" .
+					      $herecurr);
+				}
+			}
+		}
+
 # check we are in a valid source file if not then ignore this hunk
 		next if ($realfile !~ /\.(h|c|cpp|s|S|pl|py|sh)$/);