[Linux-kernel-mentees] [PATCH] checkpatch: fix false positive for REPEATED_WORD warning

Aditya yashsri421 at gmail.com
Wed Oct 21 05:15:51 UTC 2020


On 21/10/20 10:30 am, Aditya Srivastava wrote:
> Presence of hexadecimal address or symbol results in false warning
> message by checkpatch.pl.
> 
> For example, running checkpatch on commit b8ad540dd4e4 ("mptcp: fix
> memory leak in mptcp_subflow_create_socket()") results in warning:
> 
> WARNING:REPEATED_WORD: Possible repeated word: 'ff'
>     00 00 00 00 00 00 00 00 00 2f 30 0a 81 88 ff ff  ........./0.....
> 
> Here, it reports 'ff' to be repeated, but it is infact part of some
> address or code, where it has to be repeated. Thus the warning seems
> unnecessary in this case.
> 
> To avoid all such reports, add an additional regex check for a repeating
> pattern of 4 or more 2-lettered words separated by space in a line.
> 
> Signed-off-by: Aditya Srivastava <yashsri421 at gmail.com>
> ---
>  scripts/checkpatch.pl | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 9b9ffd876e8a..181c95691715 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3052,7 +3052,9 @@ sub process {
>  
>  # check for repeated words separated by a single space
>  		if ($rawline =~ /^\+/ || $in_commit_log) {
> -			while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {
> +			# avoid repeating hex occurrences like 'ff ff fe 09 ...'
> +			while ($rawline !~ /((\s)*[0-9a-z]{2}( )+){4,}/ &&
> +				$rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {
>  
>  				my $first = $1;
>  				my $second = $2;
> 


Report of the impact of patch/changes(taken over v5.6..v5.8):

List of errors and warnings after applying the patch:
https://github.com/AdityaSrivast/kernel-tasks/blob/master/Task3/summary.txt

Change in errors and warnings compared to previous patch:
https://github.com/AdityaSrivast/kernel-tasks/blob/master/Task3/relative_summary/summary_relative.txt

Impact/Conclusion:
It can be seen that a large amount of warning messages under
REPEATED_WORD were because of such hex occurrences.
The changes made reduces the warning count of REPEATED_WORD by more
than 60%, ie. from 2797 to 1015 (over v5.6..v5.8)

Aditya


More information about the Linux-kernel-mentees mailing list