Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 ///
0003 /// Zero-length and one-element arrays are deprecated, see
0004 /// Documentation/process/deprecated.rst
0005 /// Flexible-array members should be used instead.
0006 ///
0007 //
0008 // Confidence: High
0009 // Copyright: (C) 2020 Denis Efremov ISPRAS.
0010 // Comments:
0011 // Options: --no-includes --include-headers
0012 
0013 virtual context
0014 virtual report
0015 virtual org
0016 virtual patch
0017 
0018 @initialize:python@
0019 @@
0020 def relevant(positions):
0021     for p in positions:
0022         if "uapi" in p.file:
0023              return False
0024     return True
0025 
0026 @r depends on !patch@
0027 identifier name, array;
0028 type T;
0029 position p : script:python() { relevant(p) };
0030 @@
0031 
0032 (
0033   struct name {
0034     ...
0035 *   T array@p[\(0\|1\)];
0036   };
0037 |
0038   struct {
0039     ...
0040 *   T array@p[\(0\|1\)];
0041   };
0042 |
0043   union name {
0044     ...
0045 *   T array@p[\(0\|1\)];
0046   };
0047 |
0048   union {
0049     ...
0050 *   T array@p[\(0\|1\)];
0051   };
0052 )
0053 
0054 @only_field depends on patch@
0055 identifier name, array;
0056 type T;
0057 position q;
0058 @@
0059 
0060 (
0061   struct name {@q
0062     T array[0];
0063   };
0064 |
0065   struct {@q
0066     T array[0];
0067   };
0068 )
0069 
0070 @depends on patch@
0071 identifier name, array;
0072 type T;
0073 position p : script:python() { relevant(p) };
0074 // position @q with rule "only_field" simplifies
0075 // handling of bitfields, arrays, etc.
0076 position q != only_field.q;
0077 @@
0078 
0079 (
0080   struct name {@q
0081     ...
0082     T array@p[
0083 -       0
0084     ];
0085   };
0086 |
0087   struct {@q
0088     ...
0089     T array@p[
0090 -       0
0091     ];
0092   };
0093 )
0094 
0095 @script: python depends on report@
0096 p << r.p;
0097 @@
0098 
0099 msg = "WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)"
0100 coccilib.report.print_report(p[0], msg)
0101 
0102 @script: python depends on org@
0103 p << r.p;
0104 @@
0105 
0106 msg = "WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)"
0107 coccilib.org.print_todo(p[0], msg)