Skip to contentSkip to conversation

Documentation: checkpatch: add UNNECESSARY_CASTS message.

PATCH In review Vinesh Raut 2 participants 4 messages Aug 6, 2021 – Aug 9, 2021

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

PATCH v2 1/1 Documentation: checkpatch: add UNNECESSARY_CASTS message.

Add verbose description for UNNECESSARY_CASTS message type.

---
 Documentation/dev-tools/checkpatch.rst | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/dev-tools/checkpatch.rst +9 -0
index f0956e9ea2d8..9cb6b9059fc6 100644
@@ -268,6 +268,15 @@ Allocation style
 
     See: https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html
 
+   **UNNECESSAR_CASTS**
+   Cast should not be done to any alloc functions.
+   Appropriate type of pointer is pick by compiler at run time
+   Cast may hide bugs, as compiler suppress the warning after cast.
+
+   See:
+   1] https://lore.kernel.org/lkml/[email protected]/
+   2] 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
#2 lore raw
In reply to Vinesh Raut
Quoted 14 lines · Vinesh Raut

Add verbose description for UNNECESSARY_CASTS message type.

---
 Documentation/dev-tools/checkpatch.rst | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/dev-tools/checkpatch.rst +0 -0
index f0956e9ea2d8..9cb6b9059fc6 100644

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

Quoted 6 lines
Documentation/dev-tools/checkpatch.rst +3 -0
@@ -268,6 +268,15 @@ Allocation style
 
     See: https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html
 
+   **UNNECESSAR_CASTS**
+   Cast should not be done to any alloc functions.
+   Appropriate type of pointer is pick by compiler at run time

s/run time/runtime

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

Quoted 1 line
Documentation/dev-tools/checkpatch.rst +1 -0
+   Cast may hide bugs, as compiler suppress the warning after cast.

The question which arises here is what kind of bug is suppressed. Maybe follow http://c-faq.com/malloc/mallocnocast.html as checkpatch says to write up a paragraph on why it is bad.

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

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

These links are just patches that introduced the test. There is not much information about "why" they were introduced.

Other than that change the enumeration type to be
uniform with the rest of the documentation maybe?
The thing followed till now is:

See:
1. link_1
2. link_2

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

#3 lore raw
Quoted 17 lines · Dwaipayan Ray
Quoted 15 lines · Vinesh Raut

Add verbose description for UNNECESSARY_CASTS message type.

---
 Documentation/dev-tools/checkpatch.rst | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/dev-tools/checkpatch.rst +0 -0
index f0956e9ea2d8..9cb6b9059fc6 100644
@@ -268,6 +268,15 @@ Allocation style
 
Quoted 3 lines

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

Quoted 3 lines
Documentation/dev-tools/checkpatch.rst +1 -0
     See: https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html
 
+   **UNNECESSAR_CASTS**

+ **UNNECESSARY_CASTS**

Quoted 2 lines

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

Quoted 2 lines
Documentation/dev-tools/checkpatch.rst +2 -0
+   Cast should not be done to any alloc functions.
+   Appropriate type of pointer is pick by compiler at run time

+ Appropriate type of pointer is pick by compiler at runtime

Quoted 3 lines

s/run time/runtime

Quoted 1 line
Documentation/dev-tools/checkpatch.rst +1 -0
+   Cast may hide bugs, as compiler suppresses the warning after cast.

+ If a pointer is cast (wrongly), bugs like memory corruption,
segmentation faults can occur.
+ Also, It can affect functionality of the program.

Quoted 5 lines

The question which arises here is what kind of bug is suppressed. Maybe follow http://c-faq.com/malloc/mallocnocast.html as checkpatch says to write up a paragraph on why it is bad.

Quoted 7 lines

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

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

These links are just patches that introduced the test. There is not much information about "why" they were introduced.

Should I remove it?
And I didnt found any discussion on LKML regarding UNNECESSARY_CASTS issue, other than this patches.

Quoted 8 lines

Other than that change the enumeration type to be
uniform with the rest of the documentation maybe?
The thing followed till now is:

See:
1. link_1
2. link_2

+   See:
+   1. https://lore.kernel.org/lkml/[email protected]/
+   2. https://lore.kernel.org/lkml/[email protected]/
Quoted 2 lines

Dwaipayan.

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