Skip to content

Commit 41b1450

Browse files
jacob-kellerdavem330
authored andcommitted
mlx4: fix "initializer element not constant" compiler error
A recent commit e893768 ("devlink: prepare to support region operations") used the region_cr_space_str and region_fw_health_str variables as initializers for the devlink_region_ops structures. This can result in compiler errors: drivers/net/ethernet/mellanox//mlx4/crdump.c:45:10: error: initializer element is not constant .name = region_cr_space_str, ^ drivers/net/ethernet/mellanox//mlx4/crdump.c:45:10: note: (near initialization for ‘region_cr_space_ops.name’) drivers/net/ethernet/mellanox//mlx4/crdump.c:50:10: error: initializer element is not constant .name = region_fw_health_str, The variables were made to be "const char * const", indicating that both the pointer and data were constant. This was enough to resolve this on recent GCC (gcc (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1) for this author). Unfortunately this is not enough for older compilers to realize that the variable can be treated as a constant expression. Fix this by introducing macros for the string and use those instead of the variable name in the region ops structures. Reported-by: tanhuazhong <[email protected]> Fixes: e893768 ("devlink: prepare to support region operations") Signed-off-by: Jacob Keller <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9c11cc7 commit 41b1450

File tree

1 file changed

+7
-4
lines changed
  • drivers/net/ethernet/mellanox/mlx4

1 file changed

+7
-4
lines changed

drivers/net/ethernet/mellanox/mlx4/crdump.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@
3838
#define CR_ENABLE_BIT_OFFSET 0xF3F04
3939
#define MAX_NUM_OF_DUMPS_TO_STORE (8)
4040

41-
static const char * const region_cr_space_str = "cr-space";
42-
static const char * const region_fw_health_str = "fw-health";
41+
#define REGION_CR_SPACE "cr-space"
42+
#define REGION_FW_HEALTH "fw-health"
43+
44+
static const char * const region_cr_space_str = REGION_CR_SPACE;
45+
static const char * const region_fw_health_str = REGION_FW_HEALTH;
4346

4447
static const struct devlink_region_ops region_cr_space_ops = {
45-
.name = region_cr_space_str,
48+
.name = REGION_CR_SPACE,
4649
.destructor = &kvfree,
4750
};
4851

4952
static const struct devlink_region_ops region_fw_health_ops = {
50-
.name = region_fw_health_str,
53+
.name = REGION_FW_HEALTH,
5154
.destructor = &kvfree,
5255
};
5356

0 commit comments

Comments
 (0)