1 /// Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element
3 //# This makes an effort to find cases where ARRAY_SIZE can be used such as
4 //# where there is a division of sizeof the array by the sizeof its first
5 //# element or by any indexed element or the element type. It replaces the
6 //# division of the two sizeofs by ARRAY_SIZE.
9 // Copyright: (C) 2014 Himangi Saraogi. GPLv2.
11 // Options: --no-includes --include-headers
21 #include <linux/kernel.h>
23 //----------------------------------------------------------
25 //----------------------------------------------------------
27 @depends on i&&context@
32 * (sizeof(E)/sizeof(*E))
34 * (sizeof(E)/sizeof(E[...]))
36 * (sizeof(E)/sizeof(T))
39 //----------------------------------------------------------
41 //----------------------------------------------------------
48 - (sizeof(E)/sizeof(*E))
51 - (sizeof(E)/sizeof(E[...]))
54 - (sizeof(E)/sizeof(T))
58 //----------------------------------------------------------
59 // For org and report mode
60 //----------------------------------------------------------
62 @r depends on (org || report)@
68 (sizeof(E)@p /sizeof(*E))
70 (sizeof(E)@p /sizeof(E[...]))
72 (sizeof(E)@p /sizeof(T))
75 @script:python depends on org@
79 coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
81 @script:python depends on report@
85 msg="WARNING: Use ARRAY_SIZE"
86 coccilib.report.print_report(p[0], msg)