lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Fri, 24 Sep 2021 13:23:02 -0700 From: Kees Cook <keescook@...omium.org> To: Jonathan Corbet <corbet@....net> Cc: Kees Cook <keescook@...omium.org>, Linus Torvalds <torvalds@...ux-foundation.org>, Joe Perches <joe@...ches.com>, Rasmus Villemoes <linux@...musvillemoes.dk>, linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org, linux-hardening@...r.kernel.org Subject: [PATCH] docs: Explain the desired position of function attributes While discussing how to format the addition of various function attributes, some "unwritten rules" of ordering surfaced[1]. Capture a synthesized version of Linus's, Joe's, and Rasmus's recommendations on this subject for future reference. [1] https://lore.kernel.org/mm-commits/CAHk-=wiOCLRny5aifWNhr621kYrJwhfURsa0vFPeUEm8mF0ufg@mail.gmail.com Signed-off-by: Kees Cook <keescook@...omium.org> --- Documentation/process/coding-style.rst | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst index 42969ab37b34..3559c34a9281 100644 --- a/Documentation/process/coding-style.rst +++ b/Documentation/process/coding-style.rst @@ -487,6 +487,33 @@ because it is a simple way to add valuable information for the reader. Do not use the ``extern`` keyword with function prototypes as this makes lines longer and isn't strictly necessary. +When writing a function prototype, please keep the `order of elements regular +<https://lore.kernel.org/mm-commits/CAHk-=wiOCLRny5aifWNhr621kYrJwhfURsa0vFPeUEm8mF0ufg@mail.gmail.com>`_. For example:: + + __must_check __printf(4, 5) __malloc __init + static __always_inline void *action(enum magic value, size_t size, + u8 count, char *fmt, ...) + { + ... + } + +The preferred order of elements for a function prototype is: + +- attributes on the preceding lines + + - return type attributes (here, ``__must_check``) + - function parameter attributes (here, ``__printf(4,5)``) + - function behavior attributes (here, ``__malloc``) + - storage class attributes (here, ``__init``) + +- main function prototype on the next lines + + - storage class (here, ``static __always_inline`` -- even though + ``__always_inline`` is technically an attribute, it is treated like + ``inline``) + - return type (here, ``void *``) + - function name (here, ``action``) + - function parameters (as described earlier: each with type and name) 7) Centralized exiting of functions ----------------------------------- -- 2.30.2
Powered by blists - more mailing lists