From: Denis Efremov Date: Mon, 8 Mar 2021 19:12:15 +0000 (+0300) Subject: coccinelle: misc: restrict patch mode in flexible_array.cocci X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=3afb532b19df3238dede98b184bc8852517f206a;p=linux.git coccinelle: misc: restrict patch mode in flexible_array.cocci Skip patches generation for structs with a single field. Changing a zero-length array to a flexible array member in a struct with no named members breaks the compilation. However, reporting such cases is still valuable, e.g. commit 637464c59e0b ("ACPI: NFIT: Fix flexible_array.cocci warnings"). Signed-off-by: Denis Efremov Signed-off-by: Julia Lawall --- diff --git a/scripts/coccinelle/misc/flexible_array.cocci b/scripts/coccinelle/misc/flexible_array.cocci index 947fbaff82a93..f427fd68ed2d4 100644 --- a/scripts/coccinelle/misc/flexible_array.cocci +++ b/scripts/coccinelle/misc/flexible_array.cocci @@ -51,21 +51,40 @@ position p : script:python() { relevant(p) }; }; ) +@only_field depends on patch@ +identifier name, array; +type T; +position q; +@@ + +( + struct name {@q + T array[0]; + }; +| + struct {@q + T array[0]; + }; +) + @depends on patch@ identifier name, array; type T; position p : script:python() { relevant(p) }; +// position @q with rule "only_field" simplifies +// handling of bitfields, arrays, etc. +position q != only_field.q; @@ ( - struct name { + struct name {@q ... T array@p[ - 0 ]; }; | - struct { + struct {@q ... T array@p[ - 0