Skip to contentSkip to conversation

Documentation: Checkpatch.rst: Doc added UNNECESSARY_CAST

PATCH In review Vinesh Raut 2 participants 2 messages Aug 5, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Documentation: Checkpatch.rst: Doc added UNNECESSARY_CAST

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

---
 Documentation/dev-tools/checkpatch.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/dev-tools/checkpatch.rst +10 -0
index f0956e9ea2d8..72c2f32b1515 100644
@@ -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/[email protected]/
+      https://lore.kernel.org/lkml/[email protected]/
 
 API usage
 ---------
Signature · 6 lines
2.30.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
maintainer
#1 lore raw
Quoted 4 lines · Vinesh Raut

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

This message isn't particularly useful.
A simple:

Add verbose description for UNNECESSARY_CAST message type.

would have worked.

Quoted 12 lines
---
 Documentation/dev-tools/checkpatch.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/dev-tools/checkpatch.rst +0 -0
index f0956e9ea2d8..72c2f32b1515 100644

Documentation/dev-tools/checkpatch.rst Allocation style · line 273

Quoted 6 lines
Documentation/dev-tools/checkpatch.rst +3 -0
@@ -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

s/returns/return

The sentence sounds weird. Maybe refactor it a bit?

Documentation/dev-tools/checkpatch.rst Allocation style · line 275

Quoted 2 lines
Documentation/dev-tools/checkpatch.rst +2 -0
+      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.

Here too. Simpler sentences are preferred.

Documentation/dev-tools/checkpatch.rst Allocation style · line 278

Quoted 3 lines
Documentation/dev-tools/checkpatch.rst +3 -0
+
+      See:
+      http://c-faq.com/malloc/mallocnocast.html

Let's not use this link here. External websites are vulnerable to change. However lore.kernel.org links are okay.

Documentation/dev-tools/checkpatch.rst Allocation style · line 281

Quoted 3 lines
Documentation/dev-tools/checkpatch.rst +2 -0
+      https://lore.kernel.org/lkml/[email protected]/
+      https://lore.kernel.org/lkml/[email protected]/
 

You can enumerate these. See the format followed by other verbose descriptions.

Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees