OSDN Git Service

hinic: avoid gcc -Wrestrict warning
authorArnd Bergmann <arnd@arndb.de>
Wed, 24 Mar 2021 13:07:22 +0000 (14:07 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 25 Mar 2021 01:00:32 +0000 (18:00 -0700)
commit84c7f6c33f42a12eb036ebf0f0e3670799304120
treeb3e51e778574b8e4cab59ed56781390683d92c94
parent5a5586112b929546e16029261a987c9197bfdfa2
hinic: avoid gcc -Wrestrict warning

With extra warnings enabled, gcc complains that snprintf should not
take the same buffer as source and destination:

drivers/net/ethernet/huawei/hinic/hinic_ethtool.c: In function 'hinic_set_settings_to_hw':
drivers/net/ethernet/huawei/hinic/hinic_ethtool.c:480:9: error: 'snprintf' argument 4 overlaps destination object 'set_link_str' [-Werror=restrict]
  480 |   err = snprintf(set_link_str, SET_LINK_STR_MAX_LEN,
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  481 |           "%sspeed %d ", set_link_str, speed);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/huawei/hinic/hinic_ethtool.c:464:7: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
  464 |  char set_link_str[SET_LINK_STR_MAX_LEN] = {0};

Rewrite this to avoid the nested sprintf and instead use separate
buffers, which is simpler.

Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/huawei/hinic/hinic_ethtool.c