<div><br></div><div><br><div class="gmail_quote"><div dir="auto">On Mi., 25. Nov. 2020 at 20:05, Dwaipayan Ray <<a href="mailto:dwaipayanray1@gmail.com">dwaipayanray1@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Modifiers %h and %hh should never be used.<br>
<br>
Commit cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use<br>
of unnecessary %h[xudi] and %hh[xudi]") specifies that:<br>
<br>
"Standard integer promotion is already done and %hx and %hhx is useless<br>
so do not encourage the use of %hh[xudi] or %h[xudi]."<br>
<br>
"The "h" and "hh" things should never be used. The only reason for them<br>
being used if you have an "int", but you want to print it out as a<br>
"char" (and honestly, that is a really bad reason, you'd be better off<br>
just using a proper cast to make the code more obvious)."<br>
<br>
Add a new check to emit a warning on finding an unneeded use of %h or<br>
%hh modifier.<br>
</blockquote><div dir="auto"><br></div><div dir="auto">Looks good. You might want to add the link to the original email discussion on <a href="http://lore.kernel.org">lore.kernel.org</a> in the commit message with Link:</div><div dir="auto"><br></div><div dir="auto">Lukas</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Suggested-by: Lukas Bulwahn <<a href="mailto:lukas.bulwahn@gmail.com" target="_blank">lukas.bulwahn@gmail.com</a>><br>
Signed-off-by: Dwaipayan Ray <<a href="mailto:dwaipayanray1@gmail.com" target="_blank">dwaipayanray1@gmail.com</a>><br>
---<br>
 scripts/<a href="http://checkpatch.pl" rel="noreferrer" target="_blank">checkpatch.pl</a> | 13 +++++++++++++<br>
 1 file changed, 13 insertions(+)<br>
<br>
diff --git a/scripts/<a href="http://checkpatch.pl" rel="noreferrer" target="_blank">checkpatch.pl</a> b/scripts/<a href="http://checkpatch.pl" rel="noreferrer" target="_blank">checkpatch.pl</a><br>
index 7dc094445d83..47c1017a9973 100755<br>
--- a/scripts/<a href="http://checkpatch.pl" rel="noreferrer" target="_blank">checkpatch.pl</a><br>
+++ b/scripts/<a href="http://checkpatch.pl" rel="noreferrer" target="_blank">checkpatch.pl</a><br>
@@ -6570,6 +6570,19 @@ sub process {<br>
                        }<br>
                }<br>
<br>
+# check for unnecessary use of %h[xudi] and %hh[xudi]<br>
+               if ($perl_version_ok &&<br>
+                   defined $stat &&<br>
+                   $line =~ /(?:[sd]?print[kfd]|(?:pr_|drm_)(?:info|debug|warn|error))/i) {<br>
+                       my $lc = $stat =~ tr@\n@@;<br>
+                       $lc = $lc + $linenr;<br>
+                       my $stat_real = get_stat_real($linenr, $lc);<br>
+                       if ($stat_real =~ /\"[^\"]*%[\d\.\*\-]*h+[idux].*\"/i) {<br>
+                               WARN("UNNECESSARY_MODIFIER",<br>
+                                    "Unnecessary use of length modifiers %h[xudi] or %hh[xudi]\n" . "$here\n$stat_real\n");<br>
+                       }<br>
+               }<br>
+<br>
 # check for naked sscanf<br>
                if ($perl_version_ok &&<br>
                    defined $stat &&<br>
-- <br>
2.27.0<br>
<br>
</blockquote></div></div>