Whamcloud - gitweb
LU-13726 build: fix checkpatch fix matching 93/58593/4
authorAndreas Dilger <adilger@whamcloud.com>
Sun, 30 Mar 2025 18:38:38 +0000 (12:38 -0600)
committerOleg Drokin <green@whamcloud.com>
Fri, 25 Apr 2025 00:55:26 +0000 (00:55 +0000)
When the spelling.txt suspect string is a regexp, then the matched
$typo string is different from the regexp, and is not a valid key
in the $spelling_fix associative array. This generates an error:

    WARNING: 'foo' may be misspelled - perhaps 'CHECKPATCH ERROR'

because $typo is not found in $spelling_fix and $typo_fix is empty.

If $typo_fix is empty after lookup, iterate the $spelling_fix keys
to find the one matching $typo so that it can be used as $typo_fix.

Avoid length warnings from DNAME usage, improve spelling suggestion.

Test-Parameters: trivial
Fixes: d097fcc51b ("LU-18810 obd: add a parameter to enable filename encoding")
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I6d29f9470d16c340ebf5bcd2384b477bac500c13
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58593
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Colin Faber <cfaber@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
contrib/scripts/checkpatch.pl
contrib/scripts/spelling.txt

index 139061f..fbad58b 100755 (executable)
@@ -604,7 +604,7 @@ our $logFunctions = qr{(?x:
        TP_printk|
        WARN(?:_RATELIMIT|_ONCE|)|
        CDEBUG|CERROR|CNETERR|CEMERG|CL_LOCK_DEBUG|CWARN|DEBUG_REQ|LCONSOLE_[A-Z]*|
-       CERROR_SLOW|CWARN_SLOW|
+       error|CERROR_SLOW|CWARN_SLOW|
        panic|
        MODULE_[A-Z_]+|
        seq_vprintf|seq_printf|seq_puts|
@@ -954,6 +954,17 @@ if (open(my $spelling, '<', $spelling_file)) {
 
                my ($suspect, $fix) = split(/\|\|/, $line);
 
+               if ($fix =~ m/^\s*$/ || $suspect =~ m/^\s*$/) {
+                       warn "$spelling_file: missing suspect or fix on line '$line'\n";
+                       next;
+               }
+               if (exists $spelling_fix{$suspect}) {
+                       my $oldfix = $spelling_fix{$suspect};
+                       if ($oldfix ne $fix) {
+                               warn "$spelling_file: duplicate suspect '$suspect' defined to both '$oldfix' and '$fix'!\n";
+                       }
+                       next;
+               }
                $spelling_fix{$suspect} = $fix;
        }
        close($spelling);
@@ -977,6 +988,17 @@ if ($codespell) {
 
                        my ($suspect, $fix) = split(/->/, $line);
 
+                       if ($fix =~ m/^\s*$/ || $suspect =~ m/^\s*$/) {
+                               warn "$codespellfile: missing suspect or fix on line '$line'\n";
+                               next;
+                       }
+                       if (exists $spelling_fix{$suspect}) {
+                               my $oldfix = $spelling_fix{$suspect};
+                               if ($oldfix ne $fix) {
+                                       warn "$codespellfile: suspect '$suspect' defined to both '$oldfix' and '$fix'!\n";
+                               }
+                               next;
+                       }
                        $spelling_fix{$suspect} = $fix;
                }
                close($spelling);
@@ -1003,6 +1025,17 @@ if (open(my $spelling, '<', $spelling_file_userspace)) {
 
                my ($suspect, $fix) = split(/\|\|/, $line);
 
+               if ($fix =~ m/^\s*$/ || $suspect =~ m/^\s*$/) {
+                       warn "$spelling_file_userspace: missing suspect or fix on line '$line'\n";
+                       next;
+               }
+               if (exists $spelling_fix_user{$suspect}) {
+                       my $oldfix = $spelling_fix_user{$suspect};
+                       if ($oldfix ne $fix) {
+                               warn "$spelling_file_userspace: suspect '$suspect' defined to both '$oldfix' and '$fix'!\n";
+                       }
+                       next;
+               }
                $spelling_fix_user{$suspect} = $fix;
        }
        close($spelling);
@@ -3535,6 +3568,12 @@ sub process {
                                my $typo_fix = $spelling_fix_user{$typo};
                                if (!defined($typo_fix)) {
                                        $typo_fix = "CHECKPATCH ERROR";
+                                       foreach my $suspect (keys %spelling_fix_user) {
+                                               if ($typo =~ /$suspect/) {
+                                                       $typo_fix = $spelling_fix_user{$suspect};
+                                                       last;
+                                               }
+                                       }
                                }
                                my $msg_level = \&WARN;
                                $msg_level = \&CHK if ($file);
@@ -3553,6 +3592,12 @@ sub process {
                                my $typo_fix = $spelling_fix{$typo};
                                if (!defined($typo_fix)) {
                                        $typo_fix = "CHECKPATCH ERROR";
+                                       foreach my $suspect (keys %spelling_fix) {
+                                               if ($typo =~ /$suspect/) {
+                                                       $typo_fix = $spelling_fix{$suspect};
+                                                       last;
+                                               }
+                                       }
                                }
                                my $msg_level = \&WARN;
                                $msg_level = \&CHK if ($file);
@@ -3898,7 +3943,7 @@ sub process {
                                $msg_type = "";
 
                        # a Lustre message that contains embedded formatting
-                       } elsif ($line =~ /^\+\s*(?:$logFunctions\s*\()?($String(?:DFID|DOSTID)$String\s*(?:|,|\)\s*;)?\s*)$/ &&
+                       } elsif ($line =~ /^\+\s*(?:$logFunctions\s*\()?($String(?:DFID|DNAME|DOSTID)$String\s*(?:|,|\)\s*;)?\s*)$/ &&
                                 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
                                $msg_type = ""
 
index 64ad960..98bcd59 100644 (file)
@@ -45,7 +45,7 @@ __u[136][624] ocd_[a-z0-9_]*||see 'XXX README XXX' below and contact adilger@wha
 del_timer||timer_delete
 del_timer_sync||timer_delete_sync
 del_singleshot_timer_sync||timer_delete_sync
-\.\*s||DNAME
+\.\*s||DNAME and encode_fn_len()
 d_name.name||encode_fn_xxx
 DN_MAX_BONUSLEN||DN_BONUS_SIZE(dnodesize)
 DN_OLD_MAX_BONUSLEN||DN_BONUS_SIZE(DNODE_MIN_SIZE)
@@ -277,7 +277,7 @@ PAGE_CACHE_MASK||PAGE_MASK
 page_cache_release||put_page
 PAGE_CACHE_SHIFT||PAGE_SHIFT
 PAGE_CACHE_SIZE||PAGE_SIZE
-PNAME||encode_fname_luname
+PNAME||encode_fn_luname
 prandom_u32||get_random_u32
 prandom_u32_max||get_random_u32_below
 ptlrpc_req_finished||ptlrpc_req_put