1 // SPDX-License-Identifier: GPL-2.0-only
2 /// Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element
4 //# This makes an effort to find cases where ARRAY_SIZE can be used such as
5 //# where there is a division of sizeof the array by the sizeof its first
6 //# element or by any indexed element or the element type. It replaces the
7 //# division of the two sizeofs by ARRAY_SIZE.
10 // Copyright: (C) 2014 Himangi Saraogi.
12 // Options: --no-includes --include-headers
22 #include <linux/kernel.h>
24 //----------------------------------------------------------
26 //----------------------------------------------------------
28 @depends on i&&context@
33 * (sizeof(E)/sizeof(*E))
35 * (sizeof(E)/sizeof(E[...]))
37 * (sizeof(E)/sizeof(T))
40 //----------------------------------------------------------
42 //----------------------------------------------------------
49 - (sizeof(E)/sizeof(*E))
52 - (sizeof(E)/sizeof(E[...]))
55 - (sizeof(E)/sizeof(T))
59 //----------------------------------------------------------
60 // For org and report mode
61 //----------------------------------------------------------
63 @r depends on (org || report)@
69 (sizeof(E)@p /sizeof(*E))
71 (sizeof(E)@p /sizeof(E[...]))
73 (sizeof(E)@p /sizeof(T))
76 @script:python depends on org@
80 coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
82 @script:python depends on report@
86 msg="WARNING: Use ARRAY_SIZE"
87 coccilib.report.print_report(p[0], msg)