diff mbox series

[net,v1] dim: initialize all struct fields

Message ID 20220504185832.1855538-1-jesse.brandeburg@intel.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net,v1] dim: initialize all struct fields | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers fail 4 blamed authors not CCed: bvanassche@acm.org saeedm@mellanox.com davem@davemloft.net leon@kernel.org; 5 maintainers not CCed: davem@davemloft.net bvanassche@acm.org saeedm@mellanox.com talgi@nvidia.com leon@kernel.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 72 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jesse Brandeburg May 4, 2022, 6:58 p.m. UTC
The W=2 build pointed out that the code wasn't initializing all the
variables in the dim_cq_moder declarations with the struct initializers.
The net change here is zero since these structs were already static
const globals and were initialized with zeros by the compiler, but
removing compiler warnings has value in and of itself.

lib/dim/net_dim.c: At top level:
lib/dim/net_dim.c:54:9: warning: missing initializer for field ‘comps’ of ‘const struct dim_cq_moder’ [-Wmissing-field-initializers]
   54 |         NET_DIM_RX_EQE_PROFILES,
      |         ^~~~~~~~~~~~~~~~~~~~~~~
In file included from lib/dim/net_dim.c:6:
./include/linux/dim.h:45:13: note: ‘comps’ declared here
   45 |         u16 comps;
      |             ^~~~~

and repeats for the tx struct, and once you fix the comps entry then
the cq_period_mode field needs the same treatment.

Add the necessary initializers so that the fields in the struct all have
explicit values.

While here and fixing these lines, clean up the code slightly with
a conversion to explicit field initializers from anonymous ones, and fix
the super long lines by removing the word "_MODERATION" from a couple
defines only used in this file.
anon to explicit conversion example similar to used in this patch:
- struct foo foo_struct = { a, b}
+ struct foo foo_struct = { .foo_a = a, .foo_b = b)

Fixes: f8be17b81d44 ("lib/dim: Fix -Wunused-const-variable warnings")
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 lib/dim/net_dim.c | 55 ++++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 24 deletions(-)


base-commit: a0df71948e9548de819a6f1da68f5f1742258a52

Comments

Jakub Kicinski May 6, 2022, 1:40 a.m. UTC | #1
On Wed,  4 May 2022 11:58:32 -0700 Jesse Brandeburg wrote:
> The W=2 build pointed out that the code wasn't initializing all the
> variables in the dim_cq_moder declarations with the struct initializers.
> The net change here is zero since these structs were already static
> const globals and were initialized with zeros by the compiler, but
> removing compiler warnings has value in and of itself.
> 
> lib/dim/net_dim.c: At top level:
> lib/dim/net_dim.c:54:9: warning: missing initializer for field ‘comps’ of ‘const struct dim_cq_moder’ [-Wmissing-field-initializers]
>    54 |         NET_DIM_RX_EQE_PROFILES,
>       |         ^~~~~~~~~~~~~~~~~~~~~~~
> In file included from lib/dim/net_dim.c:6:
> ./include/linux/dim.h:45:13: note: ‘comps’ declared here
>    45 |         u16 comps;
>       |             ^~~~~
> 
> and repeats for the tx struct, and once you fix the comps entry then
> the cq_period_mode field needs the same treatment.
> 
> Add the necessary initializers so that the fields in the struct all have
> explicit values.
> 
> While here and fixing these lines, clean up the code slightly with
> a conversion to explicit field initializers from anonymous ones, and fix
> the super long lines by removing the word "_MODERATION" from a couple
> defines only used in this file.
> anon to explicit conversion example similar to used in this patch:
> - struct foo foo_struct = { a, b}
> + struct foo foo_struct = { .foo_a = a, .foo_b = b)
> 
> Fixes: f8be17b81d44 ("lib/dim: Fix -Wunused-const-variable warnings")
> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
> ---
>  lib/dim/net_dim.c | 55 ++++++++++++++++++++++++++---------------------
>  1 file changed, 31 insertions(+), 24 deletions(-)
> 
> diff --git a/lib/dim/net_dim.c b/lib/dim/net_dim.c
> index 06811d866775..286b5220e360 100644
> --- a/lib/dim/net_dim.c
> +++ b/lib/dim/net_dim.c
> @@ -12,41 +12,48 @@
>   *        Each profile size must be of NET_DIM_PARAMS_NUM_PROFILES
>   */
>  #define NET_DIM_PARAMS_NUM_PROFILES 5
> -#define NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE 256
> -#define NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE 128
> +#define NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE 256
> +#define NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE 128
>  #define NET_DIM_DEF_PROFILE_CQE 1
>  #define NET_DIM_DEF_PROFILE_EQE 1
>  
> +#define DIM_CQ_MODER(u, p, c, m) { \
> +	.usec = (u),		   \
> +	.pkts = (p),		   \
> +	.comps = (c),		   \
> +	.cq_period_mode = (m)	   \
> +}
> +
>  #define NET_DIM_RX_EQE_PROFILES { \
> -	{1,   NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
> -	{8,   NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
> -	{64,  NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
> -	{128, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
> -	{256, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
> +	DIM_CQ_MODER(1,   NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
> +	DIM_CQ_MODER(8,   NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
> +	DIM_CQ_MODER(64,  NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
> +	DIM_CQ_MODER(128, NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
> +	DIM_CQ_MODER(256, NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0)  \
>  }

That may give people the false impression that we always have 
to initialize all the fields to appease W=2. The most common
way of fixing this warning is to tell the compiler that we know
what we're doing and add a comma after the last member:

-	{2,  256},             \
+	{2,  256,},             \

The commit message needs to at least discuss why this direction 
was not taken. My preference would actually be to do it, tho.

Also please CC maintainers and authors of patches under Fixes:.
Jesse Brandeburg May 6, 2022, 3:28 p.m. UTC | #2
On 5/5/2022 6:40 PM, Jakub Kicinski wrote:

>>   #define NET_DIM_RX_EQE_PROFILES { \
>> -	{1,   NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
>> -	{8,   NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
>> -	{64,  NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
>> -	{128, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
>> -	{256, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
>> +	DIM_CQ_MODER(1,   NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
>> +	DIM_CQ_MODER(8,   NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
>> +	DIM_CQ_MODER(64,  NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
>> +	DIM_CQ_MODER(128, NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
>> +	DIM_CQ_MODER(256, NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0)  \
>>   }
> 
> That may give people the false impression that we always have
> to initialize all the fields to appease W=2. The most common
> way of fixing this warning is to tell the compiler that we know
> what we're doing and add a comma after the last member:
> 
> -	{2,  256},             \
> +	{2,  256,},             \
> 
> The commit message needs to at least discuss why this direction
> was not taken. My preference would actually be to do it, tho.

Ok, I'll make that change, thanks for the feedback.

> 
> Also please CC maintainers and authors of patches under Fixes:.

Yeah, my mistake and I'll fix that on the v2!

Jesse
diff mbox series

Patch

diff --git a/lib/dim/net_dim.c b/lib/dim/net_dim.c
index 06811d866775..286b5220e360 100644
--- a/lib/dim/net_dim.c
+++ b/lib/dim/net_dim.c
@@ -12,41 +12,48 @@ 
  *        Each profile size must be of NET_DIM_PARAMS_NUM_PROFILES
  */
 #define NET_DIM_PARAMS_NUM_PROFILES 5
-#define NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE 256
-#define NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE 128
+#define NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE 256
+#define NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE 128
 #define NET_DIM_DEF_PROFILE_CQE 1
 #define NET_DIM_DEF_PROFILE_EQE 1
 
+#define DIM_CQ_MODER(u, p, c, m) { \
+	.usec = (u),		   \
+	.pkts = (p),		   \
+	.comps = (c),		   \
+	.cq_period_mode = (m)	   \
+}
+
 #define NET_DIM_RX_EQE_PROFILES { \
-	{1,   NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
-	{8,   NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
-	{64,  NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
-	{128, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
-	{256, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \
+	DIM_CQ_MODER(1,   NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
+	DIM_CQ_MODER(8,   NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
+	DIM_CQ_MODER(64,  NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
+	DIM_CQ_MODER(128, NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0), \
+	DIM_CQ_MODER(256, NET_DIM_DEFAULT_RX_CQ_PKTS_FROM_EQE, 0, 0)  \
 }
 
-#define NET_DIM_RX_CQE_PROFILES { \
-	{2,  256},             \
-	{8,  128},             \
-	{16, 64},              \
-	{32, 64},              \
-	{64, 64}               \
+#define NET_DIM_RX_CQE_PROFILES {	\
+	DIM_CQ_MODER(2, 256, 0, 0),	\
+	DIM_CQ_MODER(8, 128, 0, 0),	\
+	DIM_CQ_MODER(16, 64, 0, 0),	\
+	DIM_CQ_MODER(32, 64, 0, 0),	\
+	DIM_CQ_MODER(64, 64, 0, 0)	\
 }
 
 #define NET_DIM_TX_EQE_PROFILES { \
-	{1,   NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE},  \
-	{8,   NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE},  \
-	{32,  NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE},  \
-	{64,  NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE},  \
-	{128, NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE}   \
+	DIM_CQ_MODER(1,   NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE, 0, 0), \
+	DIM_CQ_MODER(8,   NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE, 0, 0), \
+	DIM_CQ_MODER(32,  NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE, 0, 0), \
+	DIM_CQ_MODER(64,  NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE, 0, 0), \
+	DIM_CQ_MODER(128, NET_DIM_DEFAULT_TX_CQ_PKTS_FROM_EQE, 0, 0)  \
 }
 
-#define NET_DIM_TX_CQE_PROFILES { \
-	{5,  128},  \
-	{8,  64},  \
-	{16, 32},  \
-	{32, 32},  \
-	{64, 32}   \
+#define NET_DIM_TX_CQE_PROFILES {	\
+	DIM_CQ_MODER(5, 128, 0, 0),	\
+	DIM_CQ_MODER(8,  64, 0, 0),	\
+	DIM_CQ_MODER(16, 32, 0, 0),	\
+	DIM_CQ_MODER(32, 32, 0, 0),	\
+	DIM_CQ_MODER(64, 32, 0, 0)	\
 }
 
 static const struct dim_cq_moder