All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message
@ 2021-09-04  7:42 Utkarsh Verma
  2021-09-14 21:07 ` Jonathan Corbet
  0 siblings, 1 reply; 4+ messages in thread
From: Utkarsh Verma @ 2021-09-04  7:42 UTC (permalink / raw)
  To: Dwaipayan Ray
  Cc: Lukas Bulwahn, Joe Perches, Jonathan Corbet, linux-doc,
	linux-kernel, Utkarsh Verma

Add a new message type TRAILING_SEMICOLON for the macro definitions
that conclude with a semicolon.

Suggested-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Utkarsh Verma <utkarshverma294@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.
 
+  **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.25.1


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

* Re: [PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message
  2021-09-04  7:42 [PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message Utkarsh Verma
@ 2021-09-14 21:07 ` Jonathan Corbet
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Corbet @ 2021-09-14 21:07 UTC (permalink / raw)
  To: Utkarsh Verma, Dwaipayan Ray
  Cc: Lukas Bulwahn, Joe Perches, linux-doc, linux-kernel, Utkarsh Verma

Utkarsh Verma <utkarshverma294@gmail.com> writes:

> Add a new message type TRAILING_SEMICOLON for the macro definitions
> that conclude with a semicolon.
>
> Suggested-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Utkarsh Verma <utkarshverma294@gmail.com>
> ---
>  Documentation/dev-tools/checkpatch.rst | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)

Applied, thanks.

jon

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

* Re: [PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message
  2021-08-03 14:20 ` [PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message Utkarsh Verma
@ 2021-08-03 15:20   ` Dwaipayan Ray
  0 siblings, 0 replies; 4+ messages in thread
From: Dwaipayan Ray @ 2021-08-03 15:20 UTC (permalink / raw)
  To: Utkarsh Verma; +Cc: linux-kernel-mentees

On Tue, Aug 3, 2021 at 7:50 PM Utkarsh Verma <utkarshverma294@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@gmail.com>
> Suggested-by: Lukas Bulwahn <lukas.bulwahn@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.
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message
  2021-07-26 10:40 Linux Kernel: Checkpatch Documentation Mentorship Tasks Lukas Bulwahn
@ 2021-08-03 14:20 ` Utkarsh Verma
  2021-08-03 15:20   ` Dwaipayan Ray
  0 siblings, 1 reply; 4+ messages in thread
From: Utkarsh Verma @ 2021-08-03 14:20 UTC (permalink / raw)
  To: Lukas Bulwahn; +Cc: Dwaipayan Ray, linux-kernel-mentees

Add a new message type TRAILING_SEMICOLON for the macro definitions
that conclude with a semicolon.

Signed-off-by: Utkarsh Verma <utkarshverma294@gmail.com>
Suggested-by: Lukas Bulwahn <lukas.bulwahn@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::
+
+      #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.
+
   **WEAK_DECLARATION**
     Using weak declarations like __attribute__((weak)) or __weak
     can have unintended link defects.  Avoid using them.
-- 
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

end of thread, other threads:[~2021-09-14 21:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-04  7:42 [PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message Utkarsh Verma
2021-09-14 21:07 ` Jonathan Corbet
  -- strict thread matches above, loose matches on Subject: below --
2021-07-26 10:40 Linux Kernel: Checkpatch Documentation Mentorship Tasks Lukas Bulwahn
2021-08-03 14:20 ` [PATCH] Documentation: checkpatch: Add TRAILING_SEMICOLON message Utkarsh Verma
2021-08-03 15:20   ` Dwaipayan Ray

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.