mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH/RFC v2] coccinelle: of_table: Do not add commas after sentinels
@ 2025-02-05 14:28 Geert Uytterhoeven
  2025-02-05 14:36 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2025-02-05 14:28 UTC (permalink / raw)
  To: Julia Lawall, Nicolas Palix, Rob Herring, Saravana Kannan, Wolfram Sang
  Cc: cocci, devicetree, linux-kernel, Geert Uytterhoeven

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


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

end of thread, other threads:[~2025-02-05 14:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-05 14:28 [PATCH/RFC v2] coccinelle: of_table: Do not add commas after sentinels Geert Uytterhoeven
2025-02-05 14:36 ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®