|
77 | 77 |
|
78 | 78 | my %maybe_linker_symbol; # for externs in c exceptions, when seen in *vmlinux.lds.h
|
79 | 79 |
|
| 80 | +my $pending_log = undef; |
| 81 | + |
80 | 82 | sub help {
|
81 | 83 | my ($exitcode) = @_;
|
82 | 84 |
|
@@ -3898,6 +3900,91 @@ sub process {
|
3898 | 3900 | # check we are in a valid source file C or perl if not then ignore this hunk
|
3899 | 3901 | next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
|
3900 | 3902 |
|
| 3903 | +# check for pr_* and dev_* logs without a newline for C and Rust files to avoid missing log messages |
| 3904 | + my $pr_cont_pattern = qr{ |
| 3905 | + \b |
| 3906 | + pr_cont!? |
| 3907 | + \s* |
| 3908 | + \( |
| 3909 | + \s* |
| 3910 | + "([^"]*)" |
| 3911 | + [^)]* |
| 3912 | + \) |
| 3913 | + }x; |
| 3914 | + my $log_macro_pattern = qr{ |
| 3915 | + \b |
| 3916 | + ( |
| 3917 | + pr_(?:emerg|alert|crit|err|warn|notice|info|debug) |
| 3918 | + | dev_(?:emerg|alert|crit|err|warn|notice|info|dbg) |
| 3919 | + ) |
| 3920 | + (!?) |
| 3921 | + \s* |
| 3922 | + \( |
| 3923 | + \s* |
| 3924 | + "([^"]*)" |
| 3925 | + }x; |
| 3926 | + |
| 3927 | + if ($realfile =~ /\.(?:c|h|rs)$/) { |
| 3928 | + if ($rawline =~ /^\+/) { |
| 3929 | + my $cleanline = $rawline; |
| 3930 | + $cleanline =~ s/^[+\s]+//; |
| 3931 | + $cleanline =~ s/\r?$//; |
| 3932 | + $cleanline =~ s{/\*.*?\*/}{}g; |
| 3933 | + $cleanline =~ s{//.*}{}g; |
| 3934 | + |
| 3935 | + if ($pending_log) { |
| 3936 | + if ($cleanline =~ /$pr_cont_pattern/) { |
| 3937 | + my $cont_string_arg = $1; |
| 3938 | + if ($cont_string_arg =~ /\\n$/) { |
| 3939 | + $pending_log = undef; |
| 3940 | + } |
| 3941 | + } elsif ($cleanline =~ /$log_macro_pattern/) { |
| 3942 | + WARN($pending_log->{lang} . "_LOG_NO_NEWLINE", |
| 3943 | + "Possible usage of $pending_log->{macro_call} without a trailing newline.\n" . |
| 3944 | + $pending_log->{herecurr}); |
| 3945 | + |
| 3946 | + $pending_log = undef; |
| 3947 | + |
| 3948 | + my $macro_call = $1; |
| 3949 | + my $maybe_excl = $2; |
| 3950 | + my $string_arg = $3; |
| 3951 | + $string_arg =~ s/\s+$//; |
| 3952 | + |
| 3953 | + if ($realfile =~ /\.rs$/ && $maybe_excl ne '!') { |
| 3954 | + return; |
| 3955 | + } |
| 3956 | + |
| 3957 | + if ($string_arg !~ /\\n$/ && $string_arg !~ /\n$/) { |
| 3958 | + $pending_log = { |
| 3959 | + macro_call => $macro_call, |
| 3960 | + herecurr => $herecurr, |
| 3961 | + lang => ($realfile =~ /\.rs$/) ? "Rust" : "C", |
| 3962 | + }; |
| 3963 | + } |
| 3964 | + } |
| 3965 | + } else { |
| 3966 | + if ($cleanline =~ /$log_macro_pattern/) { |
| 3967 | + my $macro_call = $1; |
| 3968 | + my $maybe_excl = $2; |
| 3969 | + my $string_arg = $3; |
| 3970 | + $string_arg =~ s/\s+$//; |
| 3971 | + |
| 3972 | + if ($realfile =~ /\.rs$/ && $maybe_excl ne '!') { |
| 3973 | + return; |
| 3974 | + } |
| 3975 | + |
| 3976 | + if ($string_arg !~ /\\n$/ && $string_arg !~ /\n$/) { |
| 3977 | + $pending_log = { |
| 3978 | + macro_call => $macro_call, |
| 3979 | + herecurr => $herecurr, |
| 3980 | + lang => ($realfile =~ /\.rs$/) ? "Rust" : "C", |
| 3981 | + }; |
| 3982 | + } |
| 3983 | + } |
| 3984 | + } |
| 3985 | + } |
| 3986 | + } |
| 3987 | + |
3901 | 3988 | # at the beginning of a line any tabs must come first and anything
|
3902 | 3989 | # more than $tabsize must use tabs.
|
3903 | 3990 | if ($rawline =~ /^\+\s* \t\s*\S/ ||
|
@@ -7678,6 +7765,15 @@ sub process {
|
7678 | 7765 | }
|
7679 | 7766 | }
|
7680 | 7767 |
|
| 7768 | +# pending log means a pr_* without an ending newline has not |
| 7769 | +# been followed by a pr_cont call with a newline at the end |
| 7770 | + if ($pending_log) { |
| 7771 | + WARN($pending_log->{lang} . "_LOG_NO_NEWLINE", |
| 7772 | + "Usage of $pending_log->{macro_call} without a trailing newline.\n" . |
| 7773 | + $pending_log->{herecurr}); |
| 7774 | + $pending_log = undef; |
| 7775 | + } |
| 7776 | + |
7681 | 7777 | # If we have no input at all, then there is nothing to report on
|
7682 | 7778 | # so just keep quiet.
|
7683 | 7779 | if ($#rawlines == -1) {
|
|
0 commit comments