Skip to content

Commit 7fd8954

Browse files
Shannon NelsonJeff Kirsher
authored andcommitted
i40e: remove BUG_ON from feature string building
There's really no reason to kill the kernel thread just because of a little info string. This reworks the code to use snprintf's limiting to assure that the string is never too long, and WARN_ON to still put out a warning that we might want to look at the feature list length. Prompted by a recent Linus diatribe. Change-ID: If52ba5ca1c2344d8bf454a31bbb805eb5d2c5802 Signed-off-by: Shannon Nelson <shannon.nelson@intel.com> Tested-by: Andrew Bowers <andrewx.bowers@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
1 parent b875f99 commit 7fd8954

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10111,10 +10111,12 @@ static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
1011110111
}
1011210112

1011310113
#define INFO_STRING_LEN 255
10114+
#define REMAIN(__x) (INFO_STRING_LEN - (__x))
1011410115
static void i40e_print_features(struct i40e_pf *pf)
1011510116
{
1011610117
struct i40e_hw *hw = &pf->hw;
1011710118
char *buf, *string;
10119+
int i = 0;
1011810120

1011910121
string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
1012010122
if (!string) {
@@ -10124,42 +10126,42 @@ static void i40e_print_features(struct i40e_pf *pf)
1012410126

1012510127
buf = string;
1012610128

10127-
buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id);
10129+
i += snprintf(&buf[i], REMAIN(i), "Features: PF-id[%d] ", hw->pf_id);
1012810130
#ifdef CONFIG_PCI_IOV
10129-
buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs);
10131+
i += snprintf(&buf[i], REMAIN(i), "VFs: %d ", pf->num_req_vfs);
1013010132
#endif
10131-
buf += sprintf(buf, "VSIs: %d QP: %d RX: %s ",
10132-
pf->hw.func_caps.num_vsis,
10133-
pf->vsi[pf->lan_vsi]->num_queue_pairs,
10134-
pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF");
10133+
i += snprintf(&buf[i], REMAIN(i), "VSIs: %d QP: %d RX: %s ",
10134+
pf->hw.func_caps.num_vsis,
10135+
pf->vsi[pf->lan_vsi]->num_queue_pairs,
10136+
pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF");
1013510137

1013610138
if (pf->flags & I40E_FLAG_RSS_ENABLED)
10137-
buf += sprintf(buf, "RSS ");
10139+
i += snprintf(&buf[i], REMAIN(i), "RSS ");
1013810140
if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
10139-
buf += sprintf(buf, "FD_ATR ");
10141+
i += snprintf(&buf[i], REMAIN(i), "FD_ATR ");
1014010142
if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10141-
buf += sprintf(buf, "FD_SB ");
10142-
buf += sprintf(buf, "NTUPLE ");
10143+
i += snprintf(&buf[i], REMAIN(i), "FD_SB ");
10144+
i += snprintf(&buf[i], REMAIN(i), "NTUPLE ");
1014310145
}
1014410146
if (pf->flags & I40E_FLAG_DCB_CAPABLE)
10145-
buf += sprintf(buf, "DCB ");
10147+
i += snprintf(&buf[i], REMAIN(i), "DCB ");
1014610148
#if IS_ENABLED(CONFIG_VXLAN)
10147-
buf += sprintf(buf, "VxLAN ");
10149+
i += snprintf(&buf[i], REMAIN(i), "VxLAN ");
1014810150
#endif
1014910151
if (pf->flags & I40E_FLAG_PTP)
10150-
buf += sprintf(buf, "PTP ");
10152+
i += snprintf(&buf[i], REMAIN(i), "PTP ");
1015110153
#ifdef I40E_FCOE
1015210154
if (pf->flags & I40E_FLAG_FCOE_ENABLED)
10153-
buf += sprintf(buf, "FCOE ");
10155+
i += snprintf(&buf[i], REMAIN(i), "FCOE ");
1015410156
#endif
1015510157
if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
10156-
buf += sprintf(buf, "VEB ");
10158+
i += snprintf(&buf[i], REMAIN(i), "VEPA ");
1015710159
else
1015810160
buf += sprintf(buf, "VEPA ");
1015910161

10160-
BUG_ON(buf > (string + INFO_STRING_LEN));
1016110162
dev_info(&pf->pdev->dev, "%s\n", string);
1016210163
kfree(string);
10164+
WARN_ON(i > INFO_STRING_LEN);
1016310165
}
1016410166

1016510167
/**

0 commit comments

Comments
 (0)