Skip to content
  • Arnd Bergmann's avatar
    84c7f6c3
    hinic: avoid gcc -Wrestrict warning · 84c7f6c3
    Arnd Bergmann authored
    
    
    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: default avatarArnd Bergmann <arnd@arndb.de>
    Reviewed-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    84c7f6c3
    hinic: avoid gcc -Wrestrict warning
    Arnd Bergmann authored
    
    
    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: default avatarArnd Bergmann <arnd@arndb.de>
    Reviewed-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Loading