Messages in this thread |  | | From | Dwaipayan Ray <> | Date | Sun, 29 Nov 2020 00:34:40 +0530 | Subject | Re: [PATCH v3] checkpatch: add warning for unnecessary use of %h[xudi] and %hh[xudi] |
| |
> Here was what I tried: > > There are uses like %#06hh", so # was addedto the format block > and multiple line uses were also inspected. > > > scripts/checkpatch.pl | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 7dc094445d83..b985b6b37ba8 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -6027,6 +6027,29 @@ sub process { > "Avoid logging continuation uses where feasible\n" . $herecurr); > } > > +# check for unnecessary use of %h[xudi] and %hh[xudi] in logging functions > + if (defined $stat && > + $line =~ /\b$logFunctions\s*\(/ && > + index($stat, '"') >= 0) { > + my $lc = $stat =~ tr@\n@@; > + $lc = $lc + $linenr; > + my $stat_real = get_stat_real($linenr, $lc); > + pos($stat_real) = index($stat_real, '"'); > + my $lineoff = substr($stat_real, 0, pos($stat_real)) =~ tr/\n//; > + while ($stat_real =~ /[^"%]*(%[#\d\.\*\-]*(h+)[idux])/g) { > + my $pspec = $1; > + my $h = $2; > + if (WARN("UNNECESSARY_MODIFIER", > + "Integer promotion: '$h' use in '$pspec' is unnecessary\n" . "$here\n$stat_real\n") && > + $fix && > + $fixed[$fixlinenr + $lineoff] =~ /^\+/) { > + my $nspec = $pspec; > + $nspec =~ s/h//g; > + $fixed[$fixlinenr + $lineoff] =~ s/\Q$pspec\E/$nspec/; > + } > + } > + } > + > # check for mask then right shift without a parentheses > if ($perl_version_ok && > $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ && >
Thanks, I will modify the block according to this and send it back to you.
|  |