From: Leon Romanovsky <leon@kernel.org>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: netdev@vger.kernel.org, tanhuazhong <tanhuazhong@huawei.com>
Subject: Re: [PATCH net-next] mlx4: fix "initializer element not constant" compiler error
Date: Sun, 29 Mar 2020 09:44:49 +0300 [thread overview]
Message-ID: <20200329064449.GA2454444@unreal> (raw)
In-Reply-To: <20200327210835.2576135-1-jacob.e.keller@intel.com>
On Fri, Mar 27, 2020 at 02:08:35PM -0700, Jacob Keller wrote:
> A recent commit e8937681797c ("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 <tanhuazhong@huawei.com>
> Fixes: e8937681797c ("devlink: prepare to support region operations")
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> ---
> drivers/net/ethernet/mellanox/mlx4/crdump.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
Thanks,
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
next prev parent reply other threads:[~2020-03-29 6:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-27 21:08 [PATCH net-next] mlx4: fix "initializer element not constant" compiler error Jacob Keller
2020-03-29 6:44 ` Leon Romanovsky [this message]
2020-03-30 5:10 ` David Miller
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=20200329064449.GA2454444@unreal \
--to=leon@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=netdev@vger.kernel.org \
--cc=tanhuazhong@huawei.com \
/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).