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.

bna: adjust 'name' buf size of bna_tcb and bna_ccb structures

To have enough space to write all possible sprintf() args. Currently
'name' size is 16, but the first '%s' specifier may already need at
least 16 characters, since 'bnad->netdev->name' is used there.

For '%d' specifiers, assume that they require:
* 1 char for 'tx_id + tx_info->tcb[i]->id' sum, BNAD_MAX_TXQ_PER_TX is 8
* 2 chars for 'rx_id + rx_info->rx_ctrl[i].ccb->id', BNAD_MAX_RXP_PER_RX
is 16

And replace sprintf with snprintf.

Detected using the static analysis tool - Svace.

Fixes: 8b230ed8ec96 ("bna: Brocade 10Gb Ethernet device driver")
Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alexey Kodanev and committed by
David S. Miller
c9741a03 80ab5445

+7 -6
+1 -1
drivers/net/ethernet/brocade/bna/bna_types.h
··· 416 416 /* Tx object */ 417 417 418 418 /* Tx datapath control structure */ 419 - #define BNA_Q_NAME_SIZE 16 419 + #define BNA_Q_NAME_SIZE (IFNAMSIZ + 6) 420 420 struct bna_tcb { 421 421 /* Fast path */ 422 422 void **sw_qpt;
+6 -5
drivers/net/ethernet/brocade/bna/bnad.c
··· 1534 1534 1535 1535 for (i = 0; i < num_txqs; i++) { 1536 1536 vector_num = tx_info->tcb[i]->intr_vector; 1537 - sprintf(tx_info->tcb[i]->name, "%s TXQ %d", bnad->netdev->name, 1538 - tx_id + tx_info->tcb[i]->id); 1537 + snprintf(tx_info->tcb[i]->name, BNA_Q_NAME_SIZE, "%s TXQ %d", 1538 + bnad->netdev->name, 1539 + tx_id + tx_info->tcb[i]->id); 1539 1540 err = request_irq(bnad->msix_table[vector_num].vector, 1540 1541 (irq_handler_t)bnad_msix_tx, 0, 1541 1542 tx_info->tcb[i]->name, ··· 1586 1585 1587 1586 for (i = 0; i < num_rxps; i++) { 1588 1587 vector_num = rx_info->rx_ctrl[i].ccb->intr_vector; 1589 - sprintf(rx_info->rx_ctrl[i].ccb->name, "%s CQ %d", 1590 - bnad->netdev->name, 1591 - rx_id + rx_info->rx_ctrl[i].ccb->id); 1588 + snprintf(rx_info->rx_ctrl[i].ccb->name, BNA_Q_NAME_SIZE, 1589 + "%s CQ %d", bnad->netdev->name, 1590 + rx_id + rx_info->rx_ctrl[i].ccb->id); 1592 1591 err = request_irq(bnad->msix_table[vector_num].vector, 1593 1592 (irq_handler_t)bnad_msix_rx, 0, 1594 1593 rx_info->rx_ctrl[i].ccb->name,