^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) ///
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /// Zero-length and one-element arrays are deprecated, see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /// Documentation/process/deprecated.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) /// Flexible-array members should be used instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ///
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Confidence: High
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) // Copyright: (C) 2020 Denis Efremov ISPRAS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) // Comments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) // Options: --no-includes --include-headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) virtual context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) virtual report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) virtual org
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) virtual patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) @initialize:python@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) def relevant(positions):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) for p in positions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) if "uapi" in p.file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) return False
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) @r depends on !patch@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) identifier name, array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) type T;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) position p : script:python() { relevant(p) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct name {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * T array@p[\(0\|1\)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * T array@p[\(0\|1\)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) union name {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * T array@p[\(0\|1\)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * T array@p[\(0\|1\)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) @depends on patch@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) identifier name, array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) type T;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) position p : script:python() { relevant(p) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct name {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) T array@p[
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) - 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) T array@p[
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) - 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) @script: python depends on report@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) p << r.p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) msg = "WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) coccilib.report.print_report(p[0], msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) @script: python depends on org@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) p << r.p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) msg = "WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) coccilib.org.print_todo(p[0], msg)