[PATCH v3] Documentation: checkpatch: Add TRAILING_SEMICOLON message

Dwaipayan Ray dwaipayanray1 at gmail.com
Sun Aug 22 17:29:23 UTC 2021


On Sat, Aug 21, 2021 at 1:23 AM Utkarsh Verma <utkarshverma294 at gmail.com> wrote:
>
> Add a new message type TRAILING_SEMICOLON for the macro definitions
> that conclude with a semicolon.
>
> Suggested-by: Lukas Bulwahn <lukas.bulwahn at gmail.com>
> Signed-off-by: Utkarsh Verma <utkarshverma294 at gmail.com>
> ---
>  Documentation/dev-tools/checkpatch.rst | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
> index f0956e9ea2d8..30eda8f4a8bd 100644
> --- a/Documentation/dev-tools/checkpatch.rst
> +++ b/Documentation/dev-tools/checkpatch.rst
> @@ -845,6 +845,27 @@ Macros, Attributes and Symbols
>      Use the `fallthrough;` pseudo keyword instead of
>      `/* fallthrough */` like comments.
>

I think this is good enough.

Reviewed-by: Dwaipayan Ray <dwaipayanray1 at gmail.com>

Lukas, any inputs?

Thanks,
Dwaipayan.

> +  **TRAILING_SEMICOLON**
> +    Macro definition should not end with a semicolon. The macro
> +    invocation style should be consistent with function calls.
> +    This can prevent any unexpected code paths::
> +
> +      #define MAC do_something;
> +
> +    If this macro is used within a if else statement, like::
> +
> +      if (some_condition)
> +              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.
> +
> +    See: https://lore.kernel.org/lkml/1399671106.2912.21.camel@joe-AO725/
> +
>    **WEAK_DECLARATION**
>      Using weak declarations like __attribute__((weak)) or __weak
>      can have unintended link defects.  Avoid using them.
> --
> 2.17.1
>


More information about the Linux-kernel-mentees mailing list