netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Jesse Brandeburg <jesse.brandeburg@intel.com>
Cc: netdev@vger.kernel.org, alexandr.lobakin@intel.com
Subject: Re: [PATCH net v1] dim: initialize all struct fields
Date: Thu, 5 May 2022 18:40:33 -0700	[thread overview]
Message-ID: <20220505184033.65d7a6e5@kernel.org> (raw)
In-Reply-To: <20220504185832.1855538-1-jesse.brandeburg@intel.com>

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:.

  reply	other threads:[~2022-05-06  1:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04 18:58 [PATCH net v1] dim: initialize all struct fields Jesse Brandeburg
2022-05-06  1:40 ` Jakub Kicinski [this message]
2022-05-06 15:28   ` Jesse Brandeburg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220505184033.65d7a6e5@kernel.org \
    --to=kuba@kernel.org \
    --cc=alexandr.lobakin@intel.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).