Skip to content

Commit 31f5d9b

Browse files
anguy11Jeff Kirsher
authored andcommitted
ixgbevf: Resolve truncation warning for q_vector->name
The following warning is now shown as a result of new checks added for gcc 7: drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c: In function ‘ixgbevf_open’: drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c:1363:13: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size between 3 and 18 [-Wformat-truncation=] "%s-%s-%d", netdev->name, "TxRx", ri++); ^~ drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c:1363:6: note: directive argument in the range [0, 2147483647] "%s-%s-%d", netdev->name, "TxRx", ri++); ^~~~~~~~~~ drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c:1362:4: note: ‘snprintf’ output between 8 and 32 bytes into a destination of size 24 snprintf(q_vector->name, sizeof(q_vector->name) - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s-%s-%d", netdev->name, "TxRx", ri++); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Resolve this warning by making a couple of changes. - Don't reserve space for the null terminator. Since snprintf adds the null terminator automatically, there is no need for us to reserve a byte for it. - Change a couple variables that can never be negative from int to unsigned int. While we're making changes to the format string, move the constant strings into the format string instead of providing them as specifiers. Signed-off-by: Tony Nguyen <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 93df946 commit 31f5d9b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,23 +1351,23 @@ static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter *adapter)
13511351
{
13521352
struct net_device *netdev = adapter->netdev;
13531353
int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1354+
unsigned int ri = 0, ti = 0;
13541355
int vector, err;
1355-
int ri = 0, ti = 0;
13561356

13571357
for (vector = 0; vector < q_vectors; vector++) {
13581358
struct ixgbevf_q_vector *q_vector = adapter->q_vector[vector];
13591359
struct msix_entry *entry = &adapter->msix_entries[vector];
13601360

13611361
if (q_vector->tx.ring && q_vector->rx.ring) {
1362-
snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1363-
"%s-%s-%d", netdev->name, "TxRx", ri++);
1362+
snprintf(q_vector->name, sizeof(q_vector->name),
1363+
"%s-TxRx-%u", netdev->name, ri++);
13641364
ti++;
13651365
} else if (q_vector->rx.ring) {
1366-
snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1367-
"%s-%s-%d", netdev->name, "rx", ri++);
1366+
snprintf(q_vector->name, sizeof(q_vector->name),
1367+
"%s-rx-%u", netdev->name, ri++);
13681368
} else if (q_vector->tx.ring) {
1369-
snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1370-
"%s-%s-%d", netdev->name, "tx", ti++);
1369+
snprintf(q_vector->name, sizeof(q_vector->name),
1370+
"%s-tx-%u", netdev->name, ti++);
13711371
} else {
13721372
/* skip this unused q_vector */
13731373
continue;

0 commit comments

Comments
 (0)