Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Arnd Bergmann and committed by
David S. Miller
84c7f6c3 5a558611

+10 -15
+10 -15
drivers/net/ethernet/huawei/hinic/hinic_ethtool.c
··· 34 34 #include "hinic_rx.h" 35 35 #include "hinic_dev.h" 36 36 37 - #define SET_LINK_STR_MAX_LEN 128 37 + #define SET_LINK_STR_MAX_LEN 16 38 38 39 39 #define GET_SUPPORTED_MODE 0 40 40 #define GET_ADVERTISED_MODE 1 ··· 462 462 { 463 463 struct hinic_link_ksettings_info settings = {0}; 464 464 char set_link_str[SET_LINK_STR_MAX_LEN] = {0}; 465 + const char *autoneg_str; 465 466 struct net_device *netdev = nic_dev->netdev; 466 467 enum nic_speed_level speed_level = 0; 467 468 int err; 468 469 469 - err = snprintf(set_link_str, SET_LINK_STR_MAX_LEN, "%s", 470 - (set_settings & HILINK_LINK_SET_AUTONEG) ? 471 - (autoneg ? "autong enable " : "autong disable ") : ""); 472 - if (err < 0 || err >= SET_LINK_STR_MAX_LEN) { 473 - netif_err(nic_dev, drv, netdev, "Failed to snprintf link state, function return(%d) and dest_len(%d)\n", 474 - err, SET_LINK_STR_MAX_LEN); 475 - return -EFAULT; 476 - } 470 + autoneg_str = (set_settings & HILINK_LINK_SET_AUTONEG) ? 471 + (autoneg ? "autong enable " : "autong disable ") : ""; 477 472 478 473 if (set_settings & HILINK_LINK_SET_SPEED) { 479 474 speed_level = hinic_ethtool_to_hw_speed_level(speed); 480 475 err = snprintf(set_link_str, SET_LINK_STR_MAX_LEN, 481 - "%sspeed %d ", set_link_str, speed); 482 - if (err <= 0 || err >= SET_LINK_STR_MAX_LEN) { 476 + "speed %d ", speed); 477 + if (err >= SET_LINK_STR_MAX_LEN) { 483 478 netif_err(nic_dev, drv, netdev, "Failed to snprintf link speed, function return(%d) and dest_len(%d)\n", 484 479 err, SET_LINK_STR_MAX_LEN); 485 480 return -EFAULT; ··· 489 494 err = hinic_set_link_settings(nic_dev->hwdev, &settings); 490 495 if (err != HINIC_MGMT_CMD_UNSUPPORTED) { 491 496 if (err) 492 - netif_err(nic_dev, drv, netdev, "Set %s failed\n", 493 - set_link_str); 497 + netif_err(nic_dev, drv, netdev, "Set %s%sfailed\n", 498 + autoneg_str, set_link_str); 494 499 else 495 - netif_info(nic_dev, drv, netdev, "Set %s successfully\n", 496 - set_link_str); 500 + netif_info(nic_dev, drv, netdev, "Set %s%ssuccessfully\n", 501 + autoneg_str, set_link_str); 497 502 498 503 return err; 499 504 }