Skip to content
Commit 70eb2275 authored by Dwaipayan Ray's avatar Dwaipayan Ray Committed by Linus Torvalds
Browse files

checkpatch: add warning for unnecessary use of %h[xudi] and %hh[xudi]

Modifiers %h and %hh should never be used.

Commit cbacb5ab ("docs: printk-formats: Stop encouraging use of
unnecessary %h[xudi] and %hh[xudi]") specifies that:

 "Standard integer promotion is already done and %hx and %hhx is useless
  so do not encourage the use of %hh[xudi] or %h[xudi]."

 "The "h" and "hh" things should never be used. The only reason for them
  being used if you have an "int", but you want to print it out as a
  "char" (and honestly, that is a really bad reason, you'd be better off
  just using a proper cast to make the code more obvious)."

Add a new check to emit a warning on finding an unneeded use of %h or
%hh modifier.

Also add a fix option to the check.

Link: https://lore.kernel.org/lkml/4910042649a4f3ab22fac93191b8c1fa0a2e17c3.camel@perches.com/
Link: https://lkml.kernel.org/r/20201128200046.78739-1-dwaipayanray1@gmail.com


Signed-off-by: default avatarDwaipayan Ray <dwaipayanray1@gmail.com>
Suggested-by: default avatarJoe Perches <joe@perches.com>
Suggested-by: default avatarLukas Bulwahn <lukas.bulwahn@gmail.com>
Acked-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 831242ab
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment