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.

net: bnxt: use ethtool string helpers

Avoids having to use manual pointer manipulation.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Link: https://patch.msgid.link/20241029233229.9385-1-rosenp@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Rosen Penev and committed by
Jakub Kicinski
9b4b2e02 1441df3a

+55 -62
+55 -62
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
··· 705 705 static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) 706 706 { 707 707 struct bnxt *bp = netdev_priv(dev); 708 - static const char * const *str; 709 708 u32 i, j, num_str; 709 + const char *str; 710 710 711 711 switch (stringset) { 712 712 case ETH_SS_STATS: 713 713 for (i = 0; i < bp->cp_nr_rings; i++) { 714 - if (is_rx_ring(bp, i)) { 715 - num_str = NUM_RING_RX_HW_STATS; 716 - for (j = 0; j < num_str; j++) { 717 - sprintf(buf, "[%d]: %s", i, 718 - bnxt_ring_rx_stats_str[j]); 719 - buf += ETH_GSTRING_LEN; 714 + if (is_rx_ring(bp, i)) 715 + for (j = 0; j < NUM_RING_RX_HW_STATS; j++) { 716 + str = bnxt_ring_rx_stats_str[j]; 717 + ethtool_sprintf(&buf, "[%d]: %s", i, 718 + str); 720 719 } 721 - } 722 - if (is_tx_ring(bp, i)) { 723 - num_str = NUM_RING_TX_HW_STATS; 724 - for (j = 0; j < num_str; j++) { 725 - sprintf(buf, "[%d]: %s", i, 726 - bnxt_ring_tx_stats_str[j]); 727 - buf += ETH_GSTRING_LEN; 720 + if (is_tx_ring(bp, i)) 721 + for (j = 0; j < NUM_RING_TX_HW_STATS; j++) { 722 + str = bnxt_ring_tx_stats_str[j]; 723 + ethtool_sprintf(&buf, "[%d]: %s", i, 724 + str); 728 725 } 729 - } 730 726 num_str = bnxt_get_num_tpa_ring_stats(bp); 731 727 if (!num_str || !is_rx_ring(bp, i)) 732 728 goto skip_tpa_stats; 733 729 734 730 if (bp->max_tpa_v2) 735 - str = bnxt_ring_tpa2_stats_str; 736 - else 737 - str = bnxt_ring_tpa_stats_str; 738 - 739 - for (j = 0; j < num_str; j++) { 740 - sprintf(buf, "[%d]: %s", i, str[j]); 741 - buf += ETH_GSTRING_LEN; 742 - } 743 - skip_tpa_stats: 744 - if (is_rx_ring(bp, i)) { 745 - num_str = NUM_RING_RX_SW_STATS; 746 731 for (j = 0; j < num_str; j++) { 747 - sprintf(buf, "[%d]: %s", i, 748 - bnxt_rx_sw_stats_str[j]); 749 - buf += ETH_GSTRING_LEN; 732 + str = bnxt_ring_tpa2_stats_str[j]; 733 + ethtool_sprintf(&buf, "[%d]: %s", i, 734 + str); 750 735 } 751 - } 752 - num_str = NUM_RING_CMN_SW_STATS; 753 - for (j = 0; j < num_str; j++) { 754 - sprintf(buf, "[%d]: %s", i, 755 - bnxt_cmn_sw_stats_str[j]); 756 - buf += ETH_GSTRING_LEN; 736 + else 737 + for (j = 0; j < num_str; j++) { 738 + str = bnxt_ring_tpa_stats_str[j]; 739 + ethtool_sprintf(&buf, "[%d]: %s", i, 740 + str); 741 + } 742 + skip_tpa_stats: 743 + if (is_rx_ring(bp, i)) 744 + for (j = 0; j < NUM_RING_RX_SW_STATS; j++) { 745 + str = bnxt_rx_sw_stats_str[j]; 746 + ethtool_sprintf(&buf, "[%d]: %s", i, 747 + str); 748 + } 749 + for (j = 0; j < NUM_RING_CMN_SW_STATS; j++) { 750 + str = bnxt_cmn_sw_stats_str[j]; 751 + ethtool_sprintf(&buf, "[%d]: %s", i, str); 757 752 } 758 753 } 759 - for (i = 0; i < BNXT_NUM_RING_ERR_STATS; i++) { 760 - strscpy(buf, bnxt_ring_err_stats_arr[i], ETH_GSTRING_LEN); 761 - buf += ETH_GSTRING_LEN; 762 - } 754 + for (i = 0; i < BNXT_NUM_RING_ERR_STATS; i++) 755 + ethtool_puts(&buf, bnxt_ring_err_stats_arr[i]); 763 756 764 - if (bp->flags & BNXT_FLAG_PORT_STATS) { 757 + if (bp->flags & BNXT_FLAG_PORT_STATS) 765 758 for (i = 0; i < BNXT_NUM_PORT_STATS; i++) { 766 - strcpy(buf, bnxt_port_stats_arr[i].string); 767 - buf += ETH_GSTRING_LEN; 759 + str = bnxt_port_stats_arr[i].string; 760 + ethtool_puts(&buf, str); 768 761 } 769 - } 762 + 770 763 if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) { 771 764 u32 len; 772 765 773 766 len = min_t(u32, bp->fw_rx_stats_ext_size, 774 767 ARRAY_SIZE(bnxt_port_stats_ext_arr)); 775 768 for (i = 0; i < len; i++) { 776 - strcpy(buf, bnxt_port_stats_ext_arr[i].string); 777 - buf += ETH_GSTRING_LEN; 769 + str = bnxt_port_stats_ext_arr[i].string; 770 + ethtool_puts(&buf, str); 778 771 } 772 + 779 773 len = min_t(u32, bp->fw_tx_stats_ext_size, 780 774 ARRAY_SIZE(bnxt_tx_port_stats_ext_arr)); 781 775 for (i = 0; i < len; i++) { 782 - strcpy(buf, 783 - bnxt_tx_port_stats_ext_arr[i].string); 784 - buf += ETH_GSTRING_LEN; 776 + str = bnxt_tx_port_stats_ext_arr[i].string; 777 + ethtool_puts(&buf, str); 785 778 } 779 + 786 780 if (bp->pri2cos_valid) { 787 781 for (i = 0; i < 8; i++) { 788 - strcpy(buf, 789 - bnxt_rx_bytes_pri_arr[i].string); 790 - buf += ETH_GSTRING_LEN; 782 + str = bnxt_rx_bytes_pri_arr[i].string; 783 + ethtool_puts(&buf, str); 791 784 } 785 + 792 786 for (i = 0; i < 8; i++) { 793 - strcpy(buf, 794 - bnxt_rx_pkts_pri_arr[i].string); 795 - buf += ETH_GSTRING_LEN; 787 + str = bnxt_rx_pkts_pri_arr[i].string; 788 + ethtool_puts(&buf, str); 796 789 } 790 + 797 791 for (i = 0; i < 8; i++) { 798 - strcpy(buf, 799 - bnxt_tx_bytes_pri_arr[i].string); 800 - buf += ETH_GSTRING_LEN; 792 + str = bnxt_tx_bytes_pri_arr[i].string; 793 + ethtool_puts(&buf, str); 801 794 } 795 + 802 796 for (i = 0; i < 8; i++) { 803 - strcpy(buf, 804 - bnxt_tx_pkts_pri_arr[i].string); 805 - buf += ETH_GSTRING_LEN; 797 + str = bnxt_tx_pkts_pri_arr[i].string; 798 + ethtool_puts(&buf, str); 806 799 } 807 800 } 808 801 } 809 802 break; 810 803 case ETH_SS_TEST: 811 804 if (bp->num_tests) 812 - memcpy(buf, bp->test_info->string, 813 - bp->num_tests * ETH_GSTRING_LEN); 805 + for (i = 0; i < bp->num_tests; i++) 806 + ethtool_puts(&buf, bp->test_info->string[i]); 814 807 break; 815 808 default: 816 809 netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",