Skip to contentSkip to conversation

docs: netdev: document guidance on cleanup.h

PATCH Superseded Jakub Kicinski 5 participants 5 messages Aug 29, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 docs: netdev: document guidance on cleanup.h

Document what was discussed multiple times on list and various virtual / in-person conversations. guard() being okay in functions <= 20 LoC is my own invention. If the function is trivial it should be fine, but feel free to disagree :)

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 Documentation/process/maintainer-netdev.rst | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
Documentation/process/maintainer-netdev.rst +16 -0
index fe8616397d63..ccd6c96a169b 100644
@@ -392,6 +392,22 @@ When working in existing code which uses nonstandard formatting make
 your code follow the most recent guidelines, so that eventually all code
 in the domain of netdev is in the preferred format.
 
+Using device-managed and cleanup.h constructs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Netdev remains skeptical about promises of all "auto-cleanup" APIs,
+including even ``devm_`` helpers, historically. They are not the preferred
+style of implementation, merely an acceptable one.
+
+Use of ``guard()`` is discouraged within any function longer than 20 lines,
+``scoped_guard()`` is considered more readable. Using normal lock/unlock is
+still (weakly) preferred.
+
+Low level cleanup constructs (such as ``__free()``) can be used when building
+APIs and helpers, especially scoped interators. However, direct use of
+``__free()`` within networking core and drivers is discouraged.
+Similar guidance applies to declaring variables mid-function.
+
 Resending after review
 ~~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.46.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jakub Kicinski
Quoted 31 lines · Jakub Kicinski

Document what was discussed multiple times on list and various virtual / in-person conversations. guard() being okay in functions <= 20 LoC is my own invention. If the function is trivial it should be fine, but feel free to disagree :)

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 Documentation/process/maintainer-netdev.rst | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
Documentation/process/maintainer-netdev.rst +9 -0
index fe8616397d63..ccd6c96a169b 100644
@@ -392,6 +392,22 @@ When working in existing code which uses nonstandard formatting make
 your code follow the most recent guidelines, so that eventually all code
 in the domain of netdev is in the preferred format.
 
+Using device-managed and cleanup.h constructs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Netdev remains skeptical about promises of all "auto-cleanup" APIs,
+including even ``devm_`` helpers, historically. They are not the preferred
+style of implementation, merely an acceptable one.
+
+Use of ``guard()`` is discouraged within any function longer than 20 lines,
+``scoped_guard()`` is considered more readable. Using normal lock/unlock is

Documentation/process/maintainer-netdev.rst When working in existing code which uses nonstandard formatting make · line 413

Quoted 10 lines
Documentation/process/maintainer-netdev.rst +7 -0
+still (weakly) preferred.
+
+Low level cleanup constructs (such as ``__free()``) can be used when building
+APIs and helpers, especially scoped interators. However, direct use of
+``__free()`` within networking core and drivers is discouraged.
+Similar guidance applies to declaring variables mid-function.
+
 Resending after review
 ~~~~~~~~~~~~~~~~~~~~~~
 

Definitely and strongly agree.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Jakub Kicinski
Quoted 6 lines · Jakub Kicinski

Document what was discussed multiple times on list and various virtual / in-person conversations. guard() being okay in functions <= 20 LoC is my own invention. If the function is trivial it should be fine, but feel free to disagree :)

When discussing guard() etc, i have said we would reconsider this in a couple of years looking at the experience of other subsystems. Maybe something about this could be added to the commit message?

Otherwise:

Andrew

reviewer
#4 lore raw
In reply to Jakub Kicinski
Quoted 25 lines · Jakub Kicinski

Document what was discussed multiple times on list and various virtual / in-person conversations. guard() being okay in functions <= 20 LoC is my own invention. If the function is trivial it should be fine, but feel free to disagree :)

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 Documentation/process/maintainer-netdev.rst | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
Documentation/process/maintainer-netdev.rst +3 -0
index fe8616397d63..ccd6c96a169b 100644
@@ -392,6 +392,22 @@ When working in existing code which uses nonstandard formatting make
 your code follow the most recent guidelines, so that eventually all code
 in the domain of netdev is in the preferred format.
 
+Using device-managed and cleanup.h constructs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+

Documentation/process/maintainer-netdev.rst When working in existing code which uses nonstandard formatting make · line 407

Quoted 10 lines
Documentation/process/maintainer-netdev.rst +10 -0
+Netdev remains skeptical about promises of all "auto-cleanup" APIs,
+including even ``devm_`` helpers, historically. They are not the preferred
+style of implementation, merely an acceptable one.
+
+Use of ``guard()`` is discouraged within any function longer than 20 lines,
+``scoped_guard()`` is considered more readable. Using normal lock/unlock is
+still (weakly) preferred.
+
+Low level cleanup constructs (such as ``__free()``) can be used when building
+APIs and helpers, especially scoped interators. However, direct use of

Sorry to nit-pick: iterators

Quoted 10 lines
Documentation/process/maintainer-netdev.rst +3 -0
+``__free()`` within networking core and drivers is discouraged.
+Similar guidance applies to declaring variables mid-function.
+
 Resending after review
 ~~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.46.0