Linux kernel staging patches
 help / color / mirror / Atom feed
* [QUESTION] staging: When should static functions be marked inline?
@ 2026-11-30  8:28 Himanshu Bakshi
  2026-11-30  9:05 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Himanshu Bakshi @ 2026-11-30  8:28 UTC (permalink / raw)
  To: linux-staging

Hi everyone,

I have a question regarding the use of `static` and `static inline`
functions in the Linux kernel.

How do we decide whether a small `static` function should be marked `inline`?

For example, if a static function consists of only 2–3 lines of code,
is it worth declaring it as `static inline`, or should we generally
leave it as `static` and let the compiler decide whether to inline it?

I'd also like to understand what factors we should consider when
making this decision. Is it primarily about function call overhead,
code size, compiler optimization, or readability?

Would it be considered good practice to convert small static functions
into static inline functions, or is that generally discouraged unless
there is a specific reason?

I'd appreciate any guidance or references to relevant kernel documentation.

Thanks and regards,
Himanshu Bakshi

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [QUESTION] staging: When should static functions be marked inline?
  2026-11-30  8:28 [QUESTION] staging: When should static functions be marked inline? Himanshu Bakshi
@ 2026-11-30  9:05 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-11-30  9:05 UTC (permalink / raw)
  To: Himanshu Bakshi; +Cc: linux-staging

Generally static is enough.  The compiler often ignores the inline anyway
and decides on its own what to do.  Use __always_inline if A) the
compiler gets it wrong really and B) benchmarking shows that it needs to
be inlined.

This mostly affects new code.  With old code, just leave it as-is unless
there is a bug.  Removing the inline doesn't really make the code more
readable so it's not worth the churn.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30  9:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  8:28 [QUESTION] staging: When should static functions be marked inline? Himanshu Bakshi
2026-11-30  9:05 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox