[PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message
Dwaipayan Ray
dwaipayanray1 at gmail.com
Tue Aug 3 15:20:32 UTC 2021
On Tue, Aug 3, 2021 at 7:50 PM Utkarsh Verma <utkarshverma294 at gmail.com> wrote:
>
> Add a new message type TRAILING_SEMICOLON for the macro definitions
> that conclude with a semicolon.
>
> Signed-off-by: Utkarsh Verma <utkarshverma294 at gmail.com>
> Suggested-by: Lukas Bulwahn <lukas.bulwahn at gmail.com>
> ---
> Documentation/dev-tools/checkpatch.rst | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
> index f0956e9ea..504edd961 100644
> --- a/Documentation/dev-tools/checkpatch.rst
> +++ b/Documentation/dev-tools/checkpatch.rst
> @@ -845,6 +845,26 @@ Macros, Attributes and Symbols
> Use the `fallthrough;` pseudo keyword instead of
> `/* fallthrough */` like comments.
>
> + **TRAILING_SEMICOLON**
> + Macro definition should not conclude with a semicolon. The macro
> + invocation should be consistent with the function call. A function
> + call concludes with a semicolon, so the macro invocation must also
> + conclude with a semicolon. Suppose if a macro MAC is defined::
The objective is really to avoid unexpected code paths. The explanation
seems correct but can be shortened a bit?
These two sentences can be combined:
The macro invocation should be consistent with the function call. A function
call concludes with a semicolon (We already know this right?), so the
macro invocation
must also conclude with a semicolon.
Also let's add link to the discussion which introduced it:
https://lore.kernel.org/lkml/alpine.DEB.2.02.1405092345480.6261@ionos.tec.linutronix.de/
> +
> + #define MAC \
> + do_something;
combine it in one line?
> +
> + If this macro is used within a if else statement, like::
> +
> + if(some_condition)
space after if
> + MAC;
> + else
> + do_something;
> +
> + Then there would be a compilation error, because when the macro is
> + expanded there are two trailing semicolons, so the else branch gets
> + orphaned.
> +
> **WEAK_DECLARATION**
> Using weak declarations like __attribute__((weak)) or __weak
> can have unintended link defects. Avoid using them.
> --
> 2.17.1
>
Dwaipayan.
More information about the Linux-kernel-mentees
mailing list