[PATCH/RFC v2] coccinelle: of_table: Do not add commas after sentinels

Geert Uytterhoeven posted 1 patch 10 months, 1 week ago
scripts/coccinelle/misc/of_table.cocci | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
[PATCH/RFC v2] coccinelle: of_table: Do not add commas after sentinels
Posted by Geert Uytterhoeven 10 months, 1 week ago
It does not make sense to have a comma after a sentinel, as any new
elements must be added before the sentinel.  Hence do not add the comma
when adding the sentinel.

Include the comma after the previous entry, else it will appear after the
sentinel.

Add a comment to clarify the purpose of the empty element.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - Add devicetree people.

This is a patch I wrote last year.
My original intention was to create a Coccinelle script to remove
commas after sentinels, and annotate them, to automate the creation of
patches like commit 0256b6aeee11d705 ("pinctrl: renesas: Annotate
sentinels in tables").  Unfortunately I could not get that work (blame
it on this being my first experiment with Coccinelle).  Hence I gave up,
and instead settled for adapting the existing script to not add these
commas in the first place...

Known issues:

  1. This generates patches like:

	+	{/* sentinel */}

     while I would prefer to see:

	+	{ /* sentinel */ }

     Is there a way to do that, or should I just post-process the
     generated patches?

  2. If the array contains a "{ NULL }" element, this is still flagged
     as a missing sentinel:

	-	{ NULL }
	+	{ NULL },
	+	{},

     Note that this is a pre-existing issue.
---
 scripts/coccinelle/misc/of_table.cocci | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
index 4693ea7447534144..7ade9766dee89c70 100644
--- a/scripts/coccinelle/misc/of_table.cocci
+++ b/scripts/coccinelle/misc/of_table.cocci
@@ -37,15 +37,14 @@ struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
 	...,
 	{
 	.var = E,
--	}
-+	},
-+	{ }
+	},
++	{ /* sentinel */ }
 };
 |
 struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
 	...,
 	{ ..., E, ... },
-+	{ },
++	{ /* sentinel */ }
 };
 )
 
-- 
2.43.0
Re: [PATCH/RFC v2] coccinelle: of_table: Do not add commas after sentinels
Posted by Julia Lawall 10 months, 1 week ago

On Wed, 5 Feb 2025, Geert Uytterhoeven wrote:

> It does not make sense to have a comma after a sentinel, as any new
> elements must be added before the sentinel.  Hence do not add the comma
> when adding the sentinel.
>
> Include the comma after the previous entry, else it will appear after the
> sentinel.
>
> Add a comment to clarify the purpose of the empty element.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v2:
>   - Add devicetree people.
>
> This is a patch I wrote last year.
> My original intention was to create a Coccinelle script to remove
> commas after sentinels, and annotate them, to automate the creation of
> patches like commit 0256b6aeee11d705 ("pinctrl: renesas: Annotate
> sentinels in tables").  Unfortunately I could not get that work (blame
> it on this being my first experiment with Coccinelle).  Hence I gave up,
> and instead settled for adapting the existing script to not add these
> commas in the first place...
>
> Known issues:
>
>   1. This generates patches like:
>
> 	+	{/* sentinel */}
>
>      while I would prefer to see:
>
> 	+	{ /* sentinel */ }
>
>      Is there a way to do that, or should I just post-process the
>      generated patches?

Try running with --smpl-spacing.

julia

>
>   2. If the array contains a "{ NULL }" element, this is still flagged
>      as a missing sentinel:
>
> 	-	{ NULL }
> 	+	{ NULL },
> 	+	{},
>
>      Note that this is a pre-existing issue.
> ---
>  scripts/coccinelle/misc/of_table.cocci | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
> index 4693ea7447534144..7ade9766dee89c70 100644
> --- a/scripts/coccinelle/misc/of_table.cocci
> +++ b/scripts/coccinelle/misc/of_table.cocci
> @@ -37,15 +37,14 @@ struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
>  	...,
>  	{
>  	.var = E,
> --	}
> -+	},
> -+	{ }
> +	},
> ++	{ /* sentinel */ }
>  };
>  |
>  struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
>  	...,
>  	{ ..., E, ... },
> -+	{ },
> ++	{ /* sentinel */ }
>  };
>  )
>
> --
> 2.43.0
>
>