[PATCH net] net: stmmac: xgmac: use #define for string constants

Jiri Slaby jirislaby at kernel.org
Wed Feb 14 23:01:33 PST 2024


On 08. 02. 24, 10:48, Simon Horman wrote:
> The cited commit introduces and uses the string constants dpp_tx_err and
> dpp_rx_err. These are assigned to constant fields of the array
> dwxgmac3_error_desc.
> 
> It has been reported that on GCC 6 and 7.5.0 this results in warnings
> such as:
> 
>    .../dwxgmac2_core.c:836:20: error: initialiser element is not constant
>     { true, "TDPES0", dpp_tx_err },
> 
> I have been able to reproduce this using: GCC 7.5.0, 8.4.0, 9.4.0 and 10.5.0.
> But not GCC 13.2.0.
> 
> So it seems this effects older compilers but not newer ones.
> As Jon points out in his report, the minimum compiler supported by
> the kernel is GCC 5.1, so it does seem that this ought to be fixed.
> 
> It is not clear to me what combination of 'const', if any, would address
> this problem.

You cannot make it more const than it is now ;). (You have a const 
pointer to const data already.)

> So this patch takes of using #defines for the string
> constants

That's indeed ugly. What about NOT creating a pointer to an array at 
all? See below.

> Compile tested only.
> 
> Fixes: 46eba193d04f ("net: stmmac: xgmac: fix handling of DPP safety error for DMA channels")
> Reported-by: Jon Hunter <jonathanh at nvidia.com>
> Closes: https://lore.kernel.org/netdev/c25eb595-8d91-40ea-9f52-efa15ebafdbc@nvidia.com/
> Reported-by: kernel test robot <lkp at intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202402081135.lAxxBXHk-lkp@intel.com/
> Signed-off-by: Simon Horman <horms at kernel.org>
> ---
>   .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c    | 69 +++++++++++-----------
>   1 file changed, 35 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> index 323c57f03c93..1af2f89a0504 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> @@ -830,41 +830,42 @@ static const struct dwxgmac3_error_desc dwxgmac3_dma_errors[32]= {
>   	{ false, "UNKNOWN", "Unknown Error" }, /* 31 */
>   };
>   
> -static const char * const dpp_rx_err = "Read Rx Descriptor Parity checker Error";
> -static const char * const dpp_tx_err = "Read Tx Descriptor Parity checker Error";

The usual (even documented, I believe) way to do this is:

static const char dpp_tx_err[] = "Read Tx Descriptor Parity checker Error";

Then keep:
{ true, "TDPES0", dpp_tx_err },

Doesn't it do the right job?

> +#define DPP_RX_ERR "Read Rx Descriptor Parity checker Error"
> +#define DPP_TX_ERR "Read Tx Descriptor Parity checker Error"

thanks,
-- 
js
suse labs




More information about the linux-arm-kernel mailing list