KSPP / linux

Linux kernel source tree (Kernel Self Protection Project)
https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project
Other
83 stars 5 forks source link

"error: invalid application of ‘sizeof’ to incomplete type" in drivers/net/ethernet/mellanox/mlx5/core/en_stats.c: In function ‘mlx5e_stats_grp_pcie_num_stats’ #71

Closed GustavoARSilva closed 4 years ago

GustavoARSilva commented 4 years ago

When replacing the one-element array pcie_performance_group[0x1] with a flexible-array member in struct mlx5_ifc_mcam_enhanced_features_bits:

diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h
index b7551149458a..191c32a1f6b2 100644
--- a/include/linux/mlx5/mlx5_ifc.h
+++ b/include/linux/mlx5/mlx5_ifc.h
@@ -9022,7 +9022,7 @@ struct mlx5_ifc_mcam_enhanced_features_bits {
        u8         tx_overflow_buffer_pkt[0x1];
        u8         mtpps_enh_out_per_adj[0x1];
        u8         mtpps_fs[0x1];
-       u8         pcie_performance_group[0x1];
+       u8         pcie_performance_group[];
 };

 struct mlx5_ifc_mcam_access_reg_bits {

the following error shows up:

In file included from ./include/linux/mlx5/driver.h:52,
                 from ./include/linux/mlx5/cq.h:37,
                 from drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h:42,
                 from drivers/net/ethernet/mellanox/mlx5/core/lib/mlx5.h:36,
                 from drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:33:
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c: In function ‘mlx5e_stats_grp_pcie_num_stats’:
./include/linux/mlx5/device.h:50:39: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
   50 | #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
      |                                       ^
./include/linux/mlx5/device.h:56:43: note: in expansion of macro ‘__mlx5_bit_sz’
   56 | #define __mlx5_dw_bit_off(typ, fld) (32 - __mlx5_bit_sz(typ, fld) - (__mlx5_bit_off(typ, fld) & 0x1f))
      |                                           ^~~~~~~~~~~~~
./include/linux/mlx5/device.h:96:30: note: in expansion of macro ‘__mlx5_dw_bit_off’
   96 | __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \
      |                              ^~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:1293:2: note: in expansion of macro ‘MLX5_GET’
 1293 |  MLX5_GET(mcam_reg, (mdev)->caps.mcam, mng_feature_cap_mask.enhanced_features.fld)
      |  ^~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:953:6: note: in expansion of macro ‘MLX5_CAP_MCAM_FEATURE’
  953 |  if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
      |      ^~~~~~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:50:39: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
   50 | #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
      |                                       ^
./include/linux/mlx5/device.h:57:47: note: in expansion of macro ‘__mlx5_bit_sz’
   57 | #define __mlx5_mask(typ, fld) ((u32)((1ull << __mlx5_bit_sz(typ, fld)) - 1))
      |                                               ^~~~~~~~~~~~~
./include/linux/mlx5/device.h:97:1: note: in expansion of macro ‘__mlx5_mask’
   97 | __mlx5_mask(typ, fld))
      | ^~~~~~~~~~~
./include/linux/mlx5/device.h:1293:2: note: in expansion of macro ‘MLX5_GET’
 1293 |  MLX5_GET(mcam_reg, (mdev)->caps.mcam, mng_feature_cap_mask.enhanced_features.fld)
      |  ^~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:953:6: note: in expansion of macro ‘MLX5_CAP_MCAM_FEATURE’
  953 |  if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
      |      ^~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c: In function ‘mlx5e_stats_grp_pcie_fill_strings’:
./include/linux/mlx5/device.h:50:39: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
   50 | #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
      |                                       ^
./include/linux/mlx5/device.h:56:43: note: in expansion of macro ‘__mlx5_bit_sz’
   56 | #define __mlx5_dw_bit_off(typ, fld) (32 - __mlx5_bit_sz(typ, fld) - (__mlx5_bit_off(typ, fld) & 0x1f))
      |                                           ^~~~~~~~~~~~~
./include/linux/mlx5/device.h:96:30: note: in expansion of macro ‘__mlx5_dw_bit_off’
   96 | __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \
      |                              ^~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:1293:2: note: in expansion of macro ‘MLX5_GET’
 1293 |  MLX5_GET(mcam_reg, (mdev)->caps.mcam, mng_feature_cap_mask.enhanced_features.fld)
      |  ^~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:969:6: note: in expansion of macro ‘MLX5_CAP_MCAM_FEATURE’
  969 |  if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
      |      ^~~~~~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:50:39: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
   50 | #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
      |                                       ^
./include/linux/mlx5/device.h:57:47: note: in expansion of macro ‘__mlx5_bit_sz’
   57 | #define __mlx5_mask(typ, fld) ((u32)((1ull << __mlx5_bit_sz(typ, fld)) - 1))
      |                                               ^~~~~~~~~~~~~
./include/linux/mlx5/device.h:97:1: note: in expansion of macro ‘__mlx5_mask’
   97 | __mlx5_mask(typ, fld))
      | ^~~~~~~~~~~
./include/linux/mlx5/device.h:1293:2: note: in expansion of macro ‘MLX5_GET’
 1293 |  MLX5_GET(mcam_reg, (mdev)->caps.mcam, mng_feature_cap_mask.enhanced_features.fld)
      |  ^~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:969:6: note: in expansion of macro ‘MLX5_CAP_MCAM_FEATURE’
  969 |  if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
      |      ^~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c: In function ‘mlx5e_stats_grp_pcie_fill_stats’:
./include/linux/mlx5/device.h:50:39: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
   50 | #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
      |                                       ^
./include/linux/mlx5/device.h:56:43: note: in expansion of macro ‘__mlx5_bit_sz’
   56 | #define __mlx5_dw_bit_off(typ, fld) (32 - __mlx5_bit_sz(typ, fld) - (__mlx5_bit_off(typ, fld) & 0x1f))
      |                                           ^~~~~~~~~~~~~
./include/linux/mlx5/device.h:96:30: note: in expansion of macro ‘__mlx5_dw_bit_off’
   96 | __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \
      |                              ^~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:1293:2: note: in expansion of macro ‘MLX5_GET’
 1293 |  MLX5_GET(mcam_reg, (mdev)->caps.mcam, mng_feature_cap_mask.enhanced_features.fld)
      |  ^~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:990:6: note: in expansion of macro ‘MLX5_CAP_MCAM_FEATURE’
  990 |  if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
      |      ^~~~~~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:50:39: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
   50 | #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
      |                                       ^
./include/linux/mlx5/device.h:57:47: note: in expansion of macro ‘__mlx5_bit_sz’
   57 | #define __mlx5_mask(typ, fld) ((u32)((1ull << __mlx5_bit_sz(typ, fld)) - 1))
      |                                               ^~~~~~~~~~~~~
./include/linux/mlx5/device.h:97:1: note: in expansion of macro ‘__mlx5_mask’
   97 | __mlx5_mask(typ, fld))
      | ^~~~~~~~~~~
./include/linux/mlx5/device.h:1293:2: note: in expansion of macro ‘MLX5_GET’
 1293 |  MLX5_GET(mcam_reg, (mdev)->caps.mcam, mng_feature_cap_mask.enhanced_features.fld)
      |  ^~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:990:6: note: in expansion of macro ‘MLX5_CAP_MCAM_FEATURE’
  990 |  if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
      |      ^~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c: In function ‘mlx5e_stats_grp_pcie_update_stats’:
./include/linux/mlx5/device.h:50:39: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
   50 | #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
      |                                       ^
./include/linux/mlx5/device.h:56:43: note: in expansion of macro ‘__mlx5_bit_sz’
   56 | #define __mlx5_dw_bit_off(typ, fld) (32 - __mlx5_bit_sz(typ, fld) - (__mlx5_bit_off(typ, fld) & 0x1f))
      |                                           ^~~~~~~~~~~~~
./include/linux/mlx5/device.h:96:30: note: in expansion of macro ‘__mlx5_dw_bit_off’
   96 | __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \
      |                              ^~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:1293:2: note: in expansion of macro ‘MLX5_GET’
 1293 |  MLX5_GET(mcam_reg, (mdev)->caps.mcam, mng_feature_cap_mask.enhanced_features.fld)
      |  ^~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:1018:7: note: in expansion of macro ‘MLX5_CAP_MCAM_FEATURE’
 1018 |  if (!MLX5_CAP_MCAM_FEATURE(mdev, pcie_performance_group))
      |       ^~~~~~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:50:39: error: invalid application of ‘sizeof’ to incomplete type ‘u8[]’ {aka ‘unsigned char[]’}
   50 | #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld)
      |                                       ^
./include/linux/mlx5/device.h:57:47: note: in expansion of macro ‘__mlx5_bit_sz’
   57 | #define __mlx5_mask(typ, fld) ((u32)((1ull << __mlx5_bit_sz(typ, fld)) - 1))
      |                                               ^~~~~~~~~~~~~
./include/linux/mlx5/device.h:97:1: note: in expansion of macro ‘__mlx5_mask’
   97 | __mlx5_mask(typ, fld))
      | ^~~~~~~~~~~
./include/linux/mlx5/device.h:1293:2: note: in expansion of macro ‘MLX5_GET’
 1293 |  MLX5_GET(mcam_reg, (mdev)->caps.mcam, mng_feature_cap_mask.enhanced_features.fld)
      |  ^~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:1018:7: note: in expansion of macro ‘MLX5_CAP_MCAM_FEATURE’
 1018 |  if (!MLX5_CAP_MCAM_FEATURE(mdev, pcie_performance_group))
      |       ^~~~~~~~~~~~~~~~~~~~~
scripts/Makefile.build:266: recipe for target 'drivers/net/ethernet/mellanox/mlx5/core/en_stats.o' failed
make[5]: *** [drivers/net/ethernet/mellanox/mlx5/core/en_stats.o] Error 1
make[5]: *** Waiting for unfinished jobs....
scripts/Makefile.build:488: recipe for target 'drivers/net/ethernet/mellanox/mlx5/core' failed

See flexible-array conversions issue.

GustavoARSilva commented 4 years ago

Duplicate of https://github.com/KSPP/linux/issues/65