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

"warning: right shift count >= width of type [-Wshift-count-overflow]" in drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c: In function ‘mlx5_cmd_set_fte’ #60

Closed GustavoARSilva closed 4 years ago

GustavoARSilva commented 4 years ago

When replacing the one-element array metadata_reg_c_0[1] with a flexible-array member in struct mlx5_ifc_flow_table_fields_supported_bits:

diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h
index d50f81b5118d..414e9d820d42 100644
--- a/include/linux/mlx5/mlx5_ifc.h
+++ b/include/linux/mlx5/mlx5_ifc.h
@@ -385,7 +385,7 @@ struct mlx5_ifc_flow_table_fields_supported_bits {
    u8         metadata_reg_c_3[0x1];
    u8         metadata_reg_c_2[0x1];
    u8         metadata_reg_c_1[0x1];
-   u8         metadata_reg_c_0[0x1];
+   u8         metadata_reg_c_0[];
 };

 struct mlx5_ifc_flow_table_prop_layout_bits {

the following warnings show up:

In file included from ./include/linux/bits.h:6,
                 from ./include/linux/bitops.h:5,
                 from ./include/linux/kernel.h:12,
                 from ./include/linux/mlx5/driver.h:36,
                 from drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c:33:
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c: In function ‘mlx5_cmd_set_fte’:
./include/linux/mlx5/device.h:96:27: warning: right shift count >= width of type [-Wshift-count-overflow]
   96 | __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \
      |                           ^~
./include/vdso/bits.h:7:30: note: in definition of macro ‘BIT’
    7 | #define BIT(nr)   (UL(1) << (nr))
      |                              ^~
./include/linux/mlx5/device.h:1221:2: note: in expansion of macro ‘MLX5_GET’
 1221 |  MLX5_GET(flow_table_eswitch_cap, \
      |  ^~~~~~~~
./include/linux/mlx5/device.h:1235:2: note: in expansion of macro ‘MLX5_CAP_ESW_FLOWTABLE’
 1235 |  MLX5_CAP_ESW_FLOWTABLE(mdev, flow_table_properties_esw_acl_egress.cap)
      |  ^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h:315:35: note: in expansion of macro ‘MLX5_CAP_ESW_EGRESS_ACL’
  315 |  (type == FS_FT_ESW_EGRESS_ACL) ? MLX5_CAP_ESW_EGRESS_ACL(mdev, cap) :  \
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c:540:27: note: in expansion of macro ‘MLX5_CAP_FLOWTABLE_TYPE’
  540 |   int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
      |                           ^~~~~~~~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:96:27: warning: right shift count >= width of type [-Wshift-count-overflow]
   96 | __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \
      |                           ^~
./include/vdso/bits.h:7:30: note: in definition of macro ‘BIT’
    7 | #define BIT(nr)   (UL(1) << (nr))
      |                              ^~
./include/linux/mlx5/device.h:1221:2: note: in expansion of macro ‘MLX5_GET’
 1221 |  MLX5_GET(flow_table_eswitch_cap, \
      |  ^~~~~~~~
./include/linux/mlx5/device.h:1241:2: note: in expansion of macro ‘MLX5_CAP_ESW_FLOWTABLE’
 1241 |  MLX5_CAP_ESW_FLOWTABLE(mdev, flow_table_properties_esw_acl_ingress.cap)
      |  ^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h:316:36: note: in expansion of macro ‘MLX5_CAP_ESW_INGRESS_ACL’
  316 |  (type == FS_FT_ESW_INGRESS_ACL) ? MLX5_CAP_ESW_INGRESS_ACL(mdev, cap) :  \
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c:540:27: note: in expansion of macro ‘MLX5_CAP_FLOWTABLE_TYPE’
  540 |   int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
      |                           ^~~~~~~~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:96:27: warning: right shift count >= width of type [-Wshift-count-overflow]
   96 | __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \
      |                           ^~
./include/vdso/bits.h:7:30: note: in definition of macro ‘BIT’
    7 | #define BIT(nr)   (UL(1) << (nr))
      |                              ^~
./include/linux/mlx5/device.h:1176:2: note: in expansion of macro ‘MLX5_GET’
 1176 |  MLX5_GET(flow_table_nic_cap, mdev->caps.hca_cur[MLX5_CAP_FLOW_TABLE], cap)
      |  ^~~~~~~~
./include/linux/mlx5/device.h:1197:2: note: in expansion of macro ‘MLX5_CAP_FLOWTABLE’
 1197 |  MLX5_CAP_FLOWTABLE(mdev, flow_table_properties_nic_receive_sniffer.cap)
      |  ^~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h:318:31: note: in expansion of macro ‘MLX5_CAP_FLOWTABLE_SNIFFER_RX’
  318 |  (type == FS_FT_SNIFFER_RX) ? MLX5_CAP_FLOWTABLE_SNIFFER_RX(mdev, cap) :  \
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c:540:27: note: in expansion of macro ‘MLX5_CAP_FLOWTABLE_TYPE’
  540 |   int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
      |                           ^~~~~~~~~~~~~~~~~~~~~~~
./include/linux/mlx5/device.h:96:27: warning: right shift count >= width of type [-Wshift-count-overflow]
   96 | __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \
      |                           ^~
./include/vdso/bits.h:7:30: note: in definition of macro ‘BIT’
    7 | #define BIT(nr)   (UL(1) << (nr))
      |                              ^~
./include/linux/mlx5/device.h:1176:2: note: in expansion of macro ‘MLX5_GET’
 1176 |  MLX5_GET(flow_table_nic_cap, mdev->caps.hca_cur[MLX5_CAP_FLOW_TABLE], cap)
      |  ^~~~~~~~
./include/linux/mlx5/device.h:1209:2: note: in expansion of macro ‘MLX5_CAP_FLOWTABLE’
 1209 |  MLX5_CAP_FLOWTABLE(mdev, flow_table_properties_nic_receive_rdma.cap)
      |  ^~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h:320:28: note: in expansion of macro ‘MLX5_CAP_FLOWTABLE_RDMA_RX’
  320 |  (type == FS_FT_RDMA_RX) ? MLX5_CAP_FLOWTABLE_RDMA_RX(mdev, cap) :  \
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c:540:27: note: in expansion of macro ‘MLX5_CAP_FLOWTABLE_TYPE’
  540 |   int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
      |                           ^~~~~~~~~~~~~~~~~~~~~~~

See flexible-array conversions issue.

GustavoARSilva commented 4 years ago

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