1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00

intel: fix string truncation warnings

Fix -Wformat-truncated warnings to complete the intel directories' W=1
clean efforts. The W=1 recently got enhanced with a few new flags and
this brought up some new warnings.

Switch to using kasprintf() when possible so we always allocate the
right length strings.

summary of warnings:
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c:1425:60: warning: ‘%s’ directive output may be truncated writing 4 bytes into a region of size between 1 and 11 [-Wformat-truncation=]
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c:1425:17: note: ‘snprintf’ output between 7 and 17 bytes into a destination of size 13
drivers/net/ethernet/intel/ice/ice_ptp.c:43:27: warning: ‘%s’ directive output may be truncated writing up to 479 bytes into a region of size 64 [-Wformat-truncation=]
drivers/net/ethernet/intel/ice/ice_ptp.c:42:17: note: ‘snprintf’ output between 1 and 480 bytes into a destination of size 64
drivers/net/ethernet/intel/igb/igb_main.c:3092:53: warning: ‘%d’ directive output may be truncated writing between 1 and 5 bytes into a region of size between 1 and 13 [-Wformat-truncation=]
drivers/net/ethernet/intel/igb/igb_main.c:3092:34: note: directive argument in the range [0, 65535]
drivers/net/ethernet/intel/igb/igb_main.c:3092:34: note: directive argument in the range [0, 65535]
drivers/net/ethernet/intel/igb/igb_main.c:3090:25: note: ‘snprintf’ output between 23 and 43 bytes into a destination of size 32

Suggested-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel)
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20231017190411.2199743-2-jacob.e.keller@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jesse Brandeburg 2023-10-17 12:04:03 -07:00 committed by Jakub Kicinski
parent 50ee052b39
commit 1978d3ead8
4 changed files with 30 additions and 37 deletions

View file

@ -396,8 +396,8 @@ static void iavf_get_priv_flag_strings(struct net_device *netdev, u8 *data)
unsigned int i; unsigned int i;
for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) { for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) {
snprintf(data, ETH_GSTRING_LEN, "%s", strscpy(data, iavf_gstrings_priv_flags[i].flag_string,
iavf_gstrings_priv_flags[i].flag_string); ETH_GSTRING_LEN);
data += ETH_GSTRING_LEN; data += ETH_GSTRING_LEN;
} }
} }

View file

@ -1378,8 +1378,6 @@ void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2); VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
} }
#define IAVF_MAX_SPEED_STRLEN 13
/** /**
* iavf_print_link_message - print link up or down * iavf_print_link_message - print link up or down
* @adapter: adapter structure * @adapter: adapter structure
@ -1397,10 +1395,6 @@ static void iavf_print_link_message(struct iavf_adapter *adapter)
return; return;
} }
speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
if (!speed)
return;
if (ADV_LINK_SUPPORT(adapter)) { if (ADV_LINK_SUPPORT(adapter)) {
link_speed_mbps = adapter->link_speed_mbps; link_speed_mbps = adapter->link_speed_mbps;
goto print_link_msg; goto print_link_msg;
@ -1438,17 +1432,17 @@ static void iavf_print_link_message(struct iavf_adapter *adapter)
print_link_msg: print_link_msg:
if (link_speed_mbps > SPEED_1000) { if (link_speed_mbps > SPEED_1000) {
if (link_speed_mbps == SPEED_2500) if (link_speed_mbps == SPEED_2500) {
snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps"); speed = kasprintf(GFP_KERNEL, "%s", "2.5 Gbps");
else } else {
/* convert to Gbps inline */ /* convert to Gbps inline */
snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s", speed = kasprintf(GFP_KERNEL, "%d Gbps",
link_speed_mbps / 1000, "Gbps"); link_speed_mbps / 1000);
}
} else if (link_speed_mbps == SPEED_UNKNOWN) { } else if (link_speed_mbps == SPEED_UNKNOWN) {
snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps"); speed = kasprintf(GFP_KERNEL, "%s", "Unknown Mbps");
} else { } else {
snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s", speed = kasprintf(GFP_KERNEL, "%d Mbps", link_speed_mbps);
link_speed_mbps, "Mbps");
} }
netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed); netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);

View file

@ -39,8 +39,8 @@ ice_get_sma_config_e810t(struct ice_hw *hw, struct ptp_pin_desc *ptp_pins)
/* initialize with defaults */ /* initialize with defaults */
for (i = 0; i < NUM_PTP_PINS_E810T; i++) { for (i = 0; i < NUM_PTP_PINS_E810T; i++) {
snprintf(ptp_pins[i].name, sizeof(ptp_pins[i].name), strscpy(ptp_pins[i].name, ice_pin_desc_e810t[i].name,
"%s", ice_pin_desc_e810t[i].name); sizeof(ptp_pins[i].name));
ptp_pins[i].index = ice_pin_desc_e810t[i].index; ptp_pins[i].index = ice_pin_desc_e810t[i].index;
ptp_pins[i].func = ice_pin_desc_e810t[i].func; ptp_pins[i].func = ice_pin_desc_e810t[i].func;
ptp_pins[i].chan = ice_pin_desc_e810t[i].chan; ptp_pins[i].chan = ice_pin_desc_e810t[i].chan;

View file

@ -3069,6 +3069,7 @@ void igb_set_fw_version(struct igb_adapter *adapter)
{ {
struct e1000_hw *hw = &adapter->hw; struct e1000_hw *hw = &adapter->hw;
struct e1000_fw_version fw; struct e1000_fw_version fw;
char *lbuf;
igb_get_fw_version(hw, &fw); igb_get_fw_version(hw, &fw);
@ -3076,36 +3077,34 @@ void igb_set_fw_version(struct igb_adapter *adapter)
case e1000_i210: case e1000_i210:
case e1000_i211: case e1000_i211:
if (!(igb_get_flash_presence_i210(hw))) { if (!(igb_get_flash_presence_i210(hw))) {
snprintf(adapter->fw_version, lbuf = kasprintf(GFP_KERNEL, "%2d.%2d-%d",
sizeof(adapter->fw_version), fw.invm_major, fw.invm_minor,
"%2d.%2d-%d", fw.invm_img_type);
fw.invm_major, fw.invm_minor,
fw.invm_img_type);
break; break;
} }
fallthrough; fallthrough;
default: default:
/* if option is rom valid, display its version too */ /* if option rom is valid, display its version too */
if (fw.or_valid) { if (fw.or_valid) {
snprintf(adapter->fw_version, lbuf = kasprintf(GFP_KERNEL, "%d.%d, 0x%08x, %d.%d.%d",
sizeof(adapter->fw_version), fw.eep_major, fw.eep_minor,
"%d.%d, 0x%08x, %d.%d.%d", fw.etrack_id, fw.or_major, fw.or_build,
fw.eep_major, fw.eep_minor, fw.etrack_id, fw.or_patch);
fw.or_major, fw.or_build, fw.or_patch);
/* no option rom */ /* no option rom */
} else if (fw.etrack_id != 0X0000) { } else if (fw.etrack_id != 0X0000) {
snprintf(adapter->fw_version, lbuf = kasprintf(GFP_KERNEL, "%d.%d, 0x%08x",
sizeof(adapter->fw_version), fw.eep_major, fw.eep_minor,
"%d.%d, 0x%08x", fw.etrack_id);
fw.eep_major, fw.eep_minor, fw.etrack_id);
} else { } else {
snprintf(adapter->fw_version, lbuf = kasprintf(GFP_KERNEL, "%d.%d.%d", fw.eep_major,
sizeof(adapter->fw_version), fw.eep_minor, fw.eep_build);
"%d.%d.%d",
fw.eep_major, fw.eep_minor, fw.eep_build);
} }
break; break;
} }
/* the truncate happens here if it doesn't fit */
strscpy(adapter->fw_version, lbuf, sizeof(adapter->fw_version));
kfree(lbuf);
} }
/** /**