I made the following semantic patch:
// find the declarations in function definitions so we can ignore them
@infn@
identifier f,i;
type T;
position p;
@@
f(...) { <...
static const T i@p[] = ...;
...> }
// find declarations where the arrays have the same size
@t1@
type T1;
identifier i1;
initializer list[n] e1;
position p1!=infn.p;
@@
static const T1 i1@p1[] = {e1};
@t2@
type T2;
identifier i2;
initializer list[t1.n] e2;
position p2!=infn.p;
@@
static const T2 i2@p2[] = {e2};
// keep only those where the line number of the second is greater than the
// line number of the first
@script:ocaml@
p1 << t1.p1;
p2 << t2.p2;
@@
if (List.hd p1).line <= (List.hd p2).line then include_match(false)
// add the macro calls
@@
fresh identifier name = t1.i1 ## "_" ## t2.i2 ## "_check";
position t2.p2;
type T2;
identifier t1.i1,t2.i2;
initializer list e2;
declarer name BUILD_BUG_DECL;
@@
static const T2 i2@p2[] = {e2};
++ BUILD_BUG_DECL(name,
++ ARRAY_SIZE(i1) != ARRAY_SIZE(i2));
--------------------------------------------------
For the file drivers/net/wireless/b43/tables_lpphy.c you mentioned I get
the output below. Perhaps the first argument to BUILD_BUG_DECL is a bit
long in each case. I use spatch with the argument --smpl-spacing so it
will put a newline after that argument.
I'm not sure if all of these constraints are wanted. I don't know if it
would have any impact here, but one could perhaps check if the two arrays
are at some point used in the same function, which might show some
connection to each other.
julia
diff -u -p a/drivers/net/wireless/b43/tables_lpphy.c
b/drivers/net/wireless/b43/tables_lpphy.c
--- a/drivers/net/wireless/b43/tables_lpphy.c
+++ b/drivers/net/wireless/b43/tables_lpphy.c
@@ -733,6 +733,8 @@ static const u8 lpphy_min_sig_sq_table[]
0xbe, 0xbe, 0xbe, 0xbe, 0xc1, 0xc4, 0xc7, 0xca, 0xcd,
0xcf, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc, 0xde,
};
+BUILD_BUG_DECL(lpphy_rev2plus_noise_scale_table_lpphy_min_sig_sq_table_check,
+ ARRAY_SIZE(lpphy_rev2plus_noise_scale_table) !=
ARRAY_SIZE(lpphy_min_sig_sq_table));
static const u16 lpphy_rev01_noise_scale_table[] = {
0xa4a4, 0xa4a4, 0xa4a4, 0xa4a4, 0xa4a4, 0xa4a4, 0xa4a4, 0xa4a4, 0xa4a4,
@@ -741,6 +743,8 @@ static const u16 lpphy_rev01_noise_scale
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4c00, 0x2d36,
0x0000, 0x0000, 0x4c00, 0x2d36,
};
+BUILD_BUG_DECL(lpphy_rev01_ps_control_table_lpphy_rev01_noise_scale_table_check,
+ ARRAY_SIZE(lpphy_rev01_ps_control_table) !=
ARRAY_SIZE(lpphy_rev01_noise_scale_table));
static const u16 lpphy_rev2plus_noise_scale_table[] = {
0x00a4, 0x00a4, 0x00a4, 0x00a4, 0x00a4, 0x00a4, 0x00a4, 0x00a4, 0x00a4,
@@ -758,11 +762,17 @@ static const u16 lpphy_crs_gain_nft_tabl
0x0392, 0x03a9, 0x03c4, 0x03e1, 0x0001, 0x001f, 0x0040, 0x005e, 0x007f,
0x009e, 0x00bd, 0x00dd, 0x00fd, 0x011d, 0x013d,
};
+BUILD_BUG_DECL(lpphy_rev1_ofdm_cck_gain_table_lpphy_crs_gain_nft_table_check,
+ ARRAY_SIZE(lpphy_rev1_ofdm_cck_gain_table) !=
ARRAY_SIZE(lpphy_crs_gain_nft_table));
+BUILD_BUG_DECL(lpphy_rev0_ofdm_cck_gain_table_lpphy_crs_gain_nft_table_check,
+ ARRAY_SIZE(lpphy_rev0_ofdm_cck_gain_table) !=
ARRAY_SIZE(lpphy_crs_gain_nft_table));
static const u16 lpphy_rev01_filter_control_table[] = {
0xa0fc, 0x10fc, 0x10db, 0x20b7, 0xff93, 0x10bf, 0x109b, 0x2077, 0xff53,
0x0127,
};
+BUILD_BUG_DECL(lpphy_rev2plus_filter_control_table_lpphy_rev01_filter_control_table_check,
+ ARRAY_SIZE(lpphy_rev2plus_filter_control_table) !=
ARRAY_SIZE(lpphy_rev01_filter_control_table));
static const u32 lpphy_rev2plus_filter_control_table[] = {
0x000141fc, 0x000021fc, 0x000021b7, 0x0000416f, 0x0001ff27, 0x0000217f,
@@ -790,6 +800,8 @@ static const u8 lpphy_pll_fraction_table
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
};
+BUILD_BUG_DECL(lpphy_hf_table_lpphy_pll_fraction_table_check,
+ ARRAY_SIZE(lpphy_hf_table) != ARRAY_SIZE(lpphy_pll_fraction_table));
static const u16 lpphy_iqlo_cal_table[] = {
0x0200, 0x0300, 0x0400, 0x0600, 0x0800, 0x0b00, 0x1000, 0x1001, 0x1002,
@@ -812,6 +824,8 @@ static const u16 lpphy_rev0_ofdm_cck_gai
0x006d, 0x007d, 0x014d, 0x015d, 0x115d, 0x035d, 0x135d, 0x055d, 0x155d,
0x0d5d, 0x1d5d, 0x2d5d, 0x555d, 0x655d, 0x755d,
};
+BUILD_BUG_DECL(lpphy_rev1_ofdm_cck_gain_table_lpphy_rev0_ofdm_cck_gain_table_check,
+ ARRAY_SIZE(lpphy_rev1_ofdm_cck_gain_table) !=
ARRAY_SIZE(lpphy_rev0_ofdm_cck_gain_table));
static const u16 lpphy_rev1_ofdm_cck_gain_table[] = {
0x5000, 0x6000, 0x7000, 0x0001, 0x1001, 0x2001, 0x3001, 0x4001, 0x5001,
@@ -956,6 +970,8 @@ static const u16 lpphy_aux_gain_idx_tabl
0x0001, 0x0002, 0x0004, 0x0016, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0016,
};
+BUILD_BUG_DECL(lpphy_a0_aux_gain_idx_table_lpphy_aux_gain_idx_table_check,
+ ARRAY_SIZE(lpphy_a0_aux_gain_idx_table) !=
ARRAY_SIZE(lpphy_aux_gain_idx_table));
static const u32 lpphy_gain_value_table[] = {
0x00000008, 0x0000000e, 0x00000014, 0x0000001a, 0x000000fb, 0x00000004,
@@ -971,6 +987,8 @@ static const u32 lpphy_gain_value_table[
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000009, 0x000000f1,
0x00000000, 0x00000000,
};
+BUILD_BUG_DECL(lpphy_a0_gain_value_table_lpphy_gain_value_table_check,
+ ARRAY_SIZE(lpphy_a0_gain_value_table) != ARRAY_SIZE(lpphy_gain_value_table));
static const u16 lpphy_gain_table[] = {
0x0000, 0x0400, 0x0800, 0x0802, 0x0804, 0x0806, 0x0807, 0x0808, 0x080a,
@@ -985,6 +1003,8 @@ static const u16 lpphy_gain_table[] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
};
+BUILD_BUG_DECL(lpphy_a0_gain_table_lpphy_gain_table_check,
+ ARRAY_SIZE(lpphy_a0_gain_table) != ARRAY_SIZE(lpphy_gain_table));
static const u32 lpphy_a0_gain_idx_table[] = {
0x001111e0, 0x00652051, 0x00606055, 0x005b005a, 0x00555060, 0x00511065,
@@ -999,6 +1019,12 @@ static const u32 lpphy_a0_gain_idx_table
0x0004d6a5, 0x0004870a, 0x00044775, 0x000407e6, 0x0003d85e, 0x000398dd,
0x00036963, 0x000339f2, 0x00030a89, 0x0002db28,
};
+BUILD_BUG_DECL(lpphy_sw_control_table_lpphy_a0_gain_idx_table_check,
+ ARRAY_SIZE(lpphy_sw_control_table) != ARRAY_SIZE(lpphy_a0_gain_idx_table));
+BUILD_BUG_DECL(lpphy_papd_mult_table_lpphy_a0_gain_idx_table_check,
+ ARRAY_SIZE(lpphy_papd_mult_table) != ARRAY_SIZE(lpphy_a0_gain_idx_table));
+BUILD_BUG_DECL(lpphy_papd_eps_table_lpphy_a0_gain_idx_table_check,
+ ARRAY_SIZE(lpphy_papd_eps_table) != ARRAY_SIZE(lpphy_a0_gain_idx_table));
static const u16 lpphy_a0_aux_gain_idx_table[] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
@@ -1045,6 +1071,10 @@ static const u16 lpphy_sw_control_table[
0x0009, 0x0009, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0018,
};
+BUILD_BUG_DECL(lpphy_papd_mult_table_lpphy_sw_control_table_check,
+ ARRAY_SIZE(lpphy_papd_mult_table) != ARRAY_SIZE(lpphy_sw_control_table));
+BUILD_BUG_DECL(lpphy_papd_eps_table_lpphy_sw_control_table_check,
+ ARRAY_SIZE(lpphy_papd_eps_table) != ARRAY_SIZE(lpphy_sw_control_table));
static const u8 lpphy_hf_table[] = {
0x4b, 0x36, 0x24, 0x18, 0x49, 0x34, 0x23, 0x17, 0x48,
@@ -1064,6 +1094,8 @@ static const u32 lpphy_papd_eps_table[]
0x007ff2e3, 0x007ff2ff, 0x007ff315, 0x007ff329, 0x007ff33f, 0x007ff356,
0x007ff36e, 0x007ff39c, 0x007ff441, 0x007ff506,
};
+BUILD_BUG_DECL(lpphy_papd_mult_table_lpphy_papd_eps_table_check,
+ ARRAY_SIZE(lpphy_papd_mult_table) != ARRAY_SIZE(lpphy_papd_eps_table));
static const u32 lpphy_papd_mult_table[] = {
0x001111e0, 0x00652051, 0x00606055, 0x005b005a, 0x00555060, 0x00511065,
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)