[PATCH] Documentation: Checkpatch.rst: Doc added UNNECESSARY_CAST

Vinesh Raut vineshraut2017 at gmail.com
Thu Aug 5 10:49:45 UTC 2021


Documentation was missing for UNNECESSARY_CAST Warning.
Added it to checkpatch.rst with refers from https://lore.kernel.org
Also, pointers been mentioned in Documentation

Suggested-by: Lukas Bulwahn <lukas.bulwahn at gmail.com>
Signed-off-by: Vinesh Raut <vineshraut2017 at gmail.com>
---
 Documentation/dev-tools/checkpatch.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index f0956e9ea2d8..72c2f32b1515 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -268,6 +268,16 @@ Allocation style
 
     See: https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html
 
+   **UNNECESSARY_CASTS**
+      Any alloc functions should not be cast. Because they usually returns the
+      void pointer, which compiler then implicitly picks the type of pointer at
+      run time. Hence, casting is not prefer on any alloc functions. cast may
+      hide bugs if any exist, as compiler supresses the warnings after casting.
+
+      See:
+      http://c-faq.com/malloc/mallocnocast.html
+      https://lore.kernel.org/lkml/20070808024321.GA6316@redhat.com/
+      https://lore.kernel.org/lkml/a5e60a2b93e10baf84af063f6c8e56402273105d.camel@perches.com/
 
 API usage
 ---------
-- 
2.30.2



More information about the Linux-kernel-mentees mailing list