Skip to contentSkip to conversation

docs: netdev: Document guidance on inline functions

PATCH In review Simon Horman 6 participants 13 messages Feb 3, 2025 – Feb 4, 2025

Subsystems (4)
lore
Share & tools
lore

Simon Horman

author reviewer
#0 lore raw

PATCH 1/1 docs: netdev: Document guidance on inline functions

Document preference for non inline functions in .c files. This has been the preference for as long as I can recall and I was recently surprised to discover that it is undocumented.

---
 Documentation/process/maintainer-netdev.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/maintainer-netdev.rst +11 -0
index e497729525d5..1fbb8178b8cd 100644
@@ -408,6 +408,17 @@ at a greater cost than the value of such clean-ups.
 
 Conversely, spelling and grammar fixes are not discouraged.
 
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
+compiler to inline them as it sees fit.
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`
+
 Resending after review
 ~~~~~~~~~~~~~~~~~~~~~~
 
maintainer
#1 lore raw
Quoted 19 lines · Simon Horman

Document preference for non inline functions in .c files. This has been the preference for as long as I can recall and I was recently surprised to discover that it is undocumented.

---
 Documentation/process/maintainer-netdev.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/maintainer-netdev.rst +0 -0
index e497729525d5..1fbb8178b8cd 100644
@@ -408,6 +408,17 @@ at a greater cost than the value of such clean-ups.
 
 Conversely, spelling and grammar fixes are not discouraged.
 

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 420

Quoted 10 lines
Documentation/process/maintainer-netdev.rst +10 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
+compiler to inline them as it sees fit.
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`

I have no objection to this change, but I do wonder if it does indeed belong in the central coding-style document. I don't think anybody encourages use of "inline" these days...?

jon

#2 lore raw

Em Mon, 03 Feb 2025 08:00:56 -0700
Jonathan Corbet <[email protected]> escreveu:

Quoted 21 lines
Quoted 19 lines · Simon Horman

Document preference for non inline functions in .c files. This has been the preference for as long as I can recall and I was recently surprised to discover that it is undocumented.

---
 Documentation/process/maintainer-netdev.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/maintainer-netdev.rst +0 -0
index e497729525d5..1fbb8178b8cd 100644
@@ -408,6 +408,17 @@ at a greater cost than the value of such clean-ups.
 
 Conversely, spelling and grammar fixes are not discouraged.
 
Quoted 7 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 417

Quoted 7 lines
Documentation/process/maintainer-netdev.rst +7 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
+compiler to inline them as it sees fit.

You should probably point to chapter (12) of Documentation/process/coding-style.rst where it mentions that inline for function prototypes and as a way to replace macros are OK.

Quoted 7 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 420

Quoted 3 lines
Documentation/process/maintainer-netdev.rst +3 -0
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`  

I have no objection to this change, but I do wonder if it does indeed belong in the central coding-style document. I don't think anybody encourages use of "inline" these days...?

Indeed IMO this belongs to the coding style. I would place it close to chapter (12) at Documentation/process/coding-style.rst.

Regards,

Thanks,
Mauro

#3 lore raw

Em Mon, 3 Feb 2025 20:50:39 +0100
Mauro Carvalho Chehab <[email protected]> escreveu:

Quoted 24 lines

Em Mon, 03 Feb 2025 08:00:56 -0700
Jonathan Corbet <[email protected]> escreveu:

Quoted 21 lines
Quoted 19 lines · Simon Horman

Document preference for non inline functions in .c files. This has been the preference for as long as I can recall and I was recently surprised to discover that it is undocumented.

---
 Documentation/process/maintainer-netdev.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/maintainer-netdev.rst +0 -0
index e497729525d5..1fbb8178b8cd 100644
@@ -408,6 +408,17 @@ at a greater cost than the value of such clean-ups.
 
 Conversely, spelling and grammar fixes are not discouraged.
 
Quoted 11 lines
Quoted 7 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 417

Quoted 7 lines
Documentation/process/maintainer-netdev.rst +7 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
+compiler to inline them as it sees fit.

You should probably point to chapter (12) of Documentation/process/coding-style.rst where it mentions that inline for function prototypes and as a way to replace macros are OK.

Heh, I hit enter too quickly...

I mean:
"inline for function prototypes and as a way to replace macros on
header files (*.h) are OK."

Quoted 9 lines
Quoted 8 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 420

Quoted 4 lines
Documentation/process/maintainer-netdev.rst +3 -0
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`  

I have no objection to this change, but I do wonder if it does indeed belong in the central coding-style document. I don't think anybody encourages use of "inline" these days...?

Quoted 7 lines

Indeed IMO this belongs to the coding style. I would place it close to chapter (12) at Documentation/process/coding-style.rst.

Regards,

Thanks,
Mauro

Thanks,
Mauro

author reviewer
#4 lore raw
Quoted 39 lines · Mauro Carvalho Chehab

Em Mon, 3 Feb 2025 20:50:39 +0100
Mauro Carvalho Chehab <[email protected]> escreveu:

Quoted 24 lines

Em Mon, 03 Feb 2025 08:00:56 -0700
Jonathan Corbet <[email protected]> escreveu:

Quoted 21 lines
Quoted 19 lines · Simon Horman

Document preference for non inline functions in .c files. This has been the preference for as long as I can recall and I was recently surprised to discover that it is undocumented.

---
 Documentation/process/maintainer-netdev.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/maintainer-netdev.rst +0 -0
index e497729525d5..1fbb8178b8cd 100644
@@ -408,6 +408,17 @@ at a greater cost than the value of such clean-ups.
 
 Conversely, spelling and grammar fixes are not discouraged.
 
Quoted 11 lines
Quoted 7 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 417

Quoted 7 lines
Documentation/process/maintainer-netdev.rst +7 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
+compiler to inline them as it sees fit.

You should probably point to chapter (12) of Documentation/process/coding-style.rst where it mentions that inline for function prototypes and as a way to replace macros are OK.

Quoted 5 lines

Heh, I hit enter too quickly...

I mean:
"inline for function prototypes and as a way to replace macros on
header files (*.h) are OK."

Likewise, I responded to your previous message too quickly.

Yes, I agree something like that would be good.

Quoted 23 lines
Quoted 10 lines
Quoted 9 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 420

Quoted 5 lines
Documentation/process/maintainer-netdev.rst +3 -0
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`  

I have no objection to this change, but I do wonder if it does indeed belong in the central coding-style document. I don't think anybody encourages use of "inline" these days...?

Quoted 7 lines

Indeed IMO this belongs to the coding style. I would place it close to chapter (12) at Documentation/process/coding-style.rst.

Regards,

Thanks,
Mauro

Thanks,
Mauro

author reviewer
#5 lore raw
In reply to Mauro Carvalho Chehab
Quoted 22 lines · Mauro Carvalho Chehab

Em Mon, 03 Feb 2025 08:00:56 -0700
Jonathan Corbet <[email protected]> escreveu:

Quoted 19 lines
Quoted 17 lines · Simon Horman

Document preference for non inline functions in .c files. This has been the preference for as long as I can recall and I was recently surprised to discover that it is undocumented.

---
 Documentation/process/maintainer-netdev.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/maintainer-netdev.rst +0 -0
index e497729525d5..1fbb8178b8cd 100644
@@ -408,6 +408,17 @@ at a greater cost than the value of such clean-ups.
 
Quoted 6 lines
Quoted 6 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 414

Quoted 6 lines
Documentation/process/maintainer-netdev.rst +4 -0
 Conversely, spelling and grammar fixes are not discouraged.
 
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged

As suggested by Andrew Lunn elsewhere in this thread I will drop "static" from the line above.

Quoted 7 lines
Quoted 3 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 417

Quoted 3 lines
Documentation/process/maintainer-netdev.rst +3 -0
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
+compiler to inline them as it sees fit.

You should probably point to chapter (12) of Documentation/process/coding-style.rst where it mentions that inline for function prototypes and as a way to static replace macros are OK.

Thanks, perhaps something like this would help:

Using inline in .h files is fine and is encouraged in place of macros [reference section 12].

Quoted 11 lines
Quoted 8 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 420

Quoted 4 lines
Documentation/process/maintainer-netdev.rst +3 -0
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`  

I have no objection to this change, but I do wonder if it does indeed belong in the central coding-style document. I don't think anybody encourages use of "inline" these days...?

Indeed IMO this belongs to the coding style. I would place it close to chapter (12) at Documentation/process/coding-style.rst.

Sure, thanks to you and Jonathan for the positive feedback there. I will prepare a revised patch that updates coding-style.rst instead.

#6 lore raw
Quoted 4 lines

Thanks, perhaps something like this would help:

Using inline in .h files is fine and is encouraged in place of macros [reference section 12].

The other major use of them in headers is for stub functions when an API implementation has a Kconfig option. The question is, do we really want to start creating such a list, and have people wanting to add to it?

Andrew

author reviewer
#7 lore raw
Quoted 9 lines · Andrew Lunn
Quoted 4 lines

Thanks, perhaps something like this would help:

Using inline in .h files is fine and is encouraged in place of macros [reference section 12].

The other major use of them in headers is for stub functions when an API implementation has a Kconfig option. The question is, do we really want to start creating such a list, and have people wanting to add to it?

Good point. Maybe it is sufficient to just make the distinction between .c and .h files.

#8 lore raw
In reply to Jonathan Corbet

...

Quoted 6 lines
Quoted 6 lines
Documentation/process/maintainer-netdev.rst +6 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
Quoted 8 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 420

Quoted 4 lines
Documentation/process/maintainer-netdev.rst +4 -0
+compiler to inline them as it sees fit.
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`  

I have no objection to this change, but I do wonder if it does indeed belong in the central coding-style document. I don't think anybody encourages use of "inline" these days...?

Apart from the cases where the compiler really ought to inline something but fails to do so because it doesn't notice just how much code collapses out.
But in that case you need always_inline.

For instance get_sigset_argpack (fs/select.c) is marked inline but isn't being inlined by gcc 12.2 (clang 18 is inlining it).

I've also seen places where #defines generate much better code than inline functions because they get processed much earlier.

David

Reviewed-by on v1 1/1
#9 lore raw
In reply to Simon Horman

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 414

Quoted 6 lines

Conversely, spelling and grammar fixes are not discouraged.

Documentation/process/maintainer-netdev.rst +4 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged

I don't think 'static' is relevant here. They probably are static, if they are inline, and to avoid warnings about missing declarations. But we just prefer not to have any sort of inline functions without good justifications within a .c file.

A nit pick, so:

Andrew

author reviewer
#10 lore raw
Quoted 12 lines · Andrew Lunn

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 414

Quoted 6 lines

Conversely, spelling and grammar fixes are not discouraged.

Documentation/process/maintainer-netdev.rst +4 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged

I don't think 'static' is relevant here. They probably are static, if they are inline, and to avoid warnings about missing declarations. But we just prefer not to have any sort of inline functions without good justifications within a .c file.

Quoted 3 lines

A nit pick, so:

Thanks Andrew,

I agree that static is not helpful here, I'll drop that in a v2.

reviewer
#11 lore raw
In reply to Simon Horman

Hi Simon,

Another nit:

Quoted 19 lines · Simon Horman

Document preference for non inline functions in .c files. This has been the preference for as long as I can recall and I was recently surprised to discover that it is undocumented.

---
 Documentation/process/maintainer-netdev.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/maintainer-netdev.rst +0 -0
index e497729525d5..1fbb8178b8cd 100644
@@ -408,6 +408,17 @@ at a greater cost than the value of such clean-ups.
 
 Conversely, spelling and grammar fixes are not discouraged.
 

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 420

Quoted 10 lines
Documentation/process/maintainer-netdev.rst +10 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
+compiler to inline them as it sees fit.
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`

Is there an ending period (full stop) after that sentence? Could/should there be?

Thanks.

Quoted 6 lines
Documentation/process/maintainer-netdev.rst +1 -0
+
 Resending after review
 ~~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
~Randy
author reviewer
#12 lore raw
Quoted 24 lines · Randy Dunlap

Hi Simon,

Another nit:

Quoted 19 lines · Simon Horman

Document preference for non inline functions in .c files. This has been the preference for as long as I can recall and I was recently surprised to discover that it is undocumented.

---
 Documentation/process/maintainer-netdev.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/process/maintainer-netdev.rst +0 -0
index e497729525d5..1fbb8178b8cd 100644
@@ -408,6 +408,17 @@ at a greater cost than the value of such clean-ups.
 
 Conversely, spelling and grammar fixes are not discouraged.
 
Quoted 13 lines

Documentation/process/maintainer-netdev.rst at a greater cost than the value of such clean-ups. · line 420

Quoted 10 lines
Documentation/process/maintainer-netdev.rst +10 -0
+Inline functions
+----------------
+
+The use of static inline functions in .c file is strongly discouraged
+unless there is a demonstrable reason for them, usually performance
+related. Rather, it is preferred to omit the inline keyword and allow the
+compiler to inline them as it sees fit.
+
+This is a stricter requirement than that of the general Linux Kernel
+:ref:`Coding Style<codingstyle>`

Is there an ending period (full stop) after that sentence? Could/should there be?

Thanks,

I think so. I will add one.