intel: fix format warnings
authorJesse Brandeburg <jesse.brandeburg@intel.com>
Tue, 17 Oct 2023 19:04:04 +0000 (12:04 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 19 Oct 2023 01:10:17 +0000 (18:10 -0700)
Get ahead of the game and fix all the -Wformat=2 noted warnings in the
intel drivers directory.

There are one set of i40e and iavf warnings I couldn't figure out how to
fix because the driver is already using vsnprintf without an explicit
"const char *" format string.

Tested with both gcc-12 and clang-15. I found gcc-12 runs clean after
this series but clang-15 is a little worried about the vsnprintf lines.

summary of warnings:

drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c:148:34: warning: format string is not a string literal [-Wformat-nonliteral]
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c:1416:24: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c:1416:24: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c:1421:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c:1421:6: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/igc/igc_ethtool.c:776:24: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/igc/igc_ethtool.c:776:24: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/igc/igc_ethtool.c:779:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/igc/igc_ethtool.c:779:6: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/iavf/iavf_ethtool.c:199:34: warning: format string is not a string literal [-Wformat-nonliteral]
drivers/net/ethernet/intel/igb/igb_ethtool.c:2360:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/igb/igb_ethtool.c:2360:6: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/igb/igb_ethtool.c:2363:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/igb/igb_ethtool.c:2363:6: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/i40e/i40e_ethtool.c:208:34: warning: format string is not a string literal [-Wformat-nonliteral]
drivers/net/ethernet/intel/i40e/i40e_ethtool.c:2515:23: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/i40e/i40e_ethtool.c:2515:23: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/i40e/i40e_ethtool.c:2519:23: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/i40e/i40e_ethtool.c:2519:23: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/ice/ice_ethtool.c:1064:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/ice/ice_ethtool.c:1064:6: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/ice/ice_ethtool.c:1084:6: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/ice/ice_ethtool.c:1084:6: note: treat the string as an argument to avoid this
drivers/net/ethernet/intel/ice/ice_ethtool.c:1100:24: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
drivers/net/ethernet/intel/ice/ice_ethtool.c:1100:24: note: treat the string as an argument to avoid this

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-3-jacob.e.keller@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/intel/i40e/i40e_ethtool.c
drivers/net/ethernet/intel/iavf/iavf_ethtool.c
drivers/net/ethernet/intel/ice/ice_ethtool.c
drivers/net/ethernet/intel/igb/igb_ethtool.c
drivers/net/ethernet/intel/igc/igc_ethtool.c
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c

index ebf36f76c0d7d9e3e641453f0536728264ed97ff..fd7163128c4dad0c67ca431d4aa786bec3503022 100644 (file)
@@ -2514,11 +2514,13 @@ static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)
        u8 *p = data;
 
        for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++)
-               ethtool_sprintf(&p, i40e_gstrings_priv_flags[i].flag_string);
+               ethtool_sprintf(&p, "%s",
+                               i40e_gstrings_priv_flags[i].flag_string);
        if (pf->hw.pf_id != 0)
                return;
        for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++)
-               ethtool_sprintf(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
+               ethtool_sprintf(&p, "%s",
+                               i40e_gl_gstrings_priv_flags[i].flag_string);
 }
 
 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
index 9246172c9c334c14abdffdd751c6d844dbe586f0..6f236d1a6444e83cd86abed8c51c1d744ed642f4 100644 (file)
@@ -395,11 +395,9 @@ static void iavf_get_priv_flag_strings(struct net_device *netdev, u8 *data)
 {
        unsigned int i;
 
-       for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) {
-               strscpy(data, iavf_gstrings_priv_flags[i].flag_string,
-                       ETH_GSTRING_LEN);
-               data += ETH_GSTRING_LEN;
-       }
+       for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++)
+               ethtool_sprintf(&data, "%s",
+                               iavf_gstrings_priv_flags[i].flag_string);
 }
 
 /**
index d406eca03cde656fae6337015f50033ce7943e43..7870a39845473682e0271ebb0a51af16b2672232 100644 (file)
@@ -1133,7 +1133,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
        switch (stringset) {
        case ETH_SS_STATS:
                for (i = 0; i < ICE_VSI_STATS_LEN; i++)
-                       ethtool_sprintf(&p,
+                       ethtool_sprintf(&p, "%s",
                                        ice_gstrings_vsi_stats[i].stat_string);
 
                if (ice_is_port_repr_netdev(netdev))
@@ -1153,7 +1153,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
                        return;
 
                for (i = 0; i < ICE_PF_STATS_LEN; i++)
-                       ethtool_sprintf(&p,
+                       ethtool_sprintf(&p, "%s",
                                        ice_gstrings_pf_stats[i].stat_string);
 
                for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
@@ -1170,7 +1170,8 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
                break;
        case ETH_SS_PRIV_FLAGS:
                for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
-                       ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name);
+                       ethtool_sprintf(&p, "%s",
+                                       ice_gstrings_priv_flags[i].name);
                break;
        default:
                break;
index 319ed601eaa1e9827e7fab48c6d13b01e2bedff1..9cbd35b6df43dd06fc9db979ea9e17981f32e400 100644 (file)
@@ -2356,10 +2356,10 @@ static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
                break;
        case ETH_SS_STATS:
                for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
-                       ethtool_sprintf(&p,
+                       ethtool_sprintf(&p, "%s",
                                        igb_gstrings_stats[i].stat_string);
                for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
-                       ethtool_sprintf(&p,
+                       ethtool_sprintf(&p, "%s",
                                        igb_gstrings_net_stats[i].stat_string);
                for (i = 0; i < adapter->num_tx_queues; i++) {
                        ethtool_sprintf(&p, "tx_queue_%u_packets", i);
index 7ab6dd58e40013614a9174686200841393530e30..bf4f611286ae382bb0bf945fc09ac21375e2cb51 100644 (file)
@@ -773,9 +773,10 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
                break;
        case ETH_SS_STATS:
                for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
-                       ethtool_sprintf(&p, igc_gstrings_stats[i].stat_string);
+                       ethtool_sprintf(&p, "%s",
+                                       igc_gstrings_stats[i].stat_string);
                for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
-                       ethtool_sprintf(&p,
+                       ethtool_sprintf(&p, "%s",
                                        igc_gstrings_net_stats[i].stat_string);
                for (i = 0; i < adapter->num_tx_queues; i++) {
                        ethtool_sprintf(&p, "tx_queue_%u_packets", i);
index 0bbad4a5cc2f5eeeac64f2cc5b8d0692996ea8a3..4dd897806fa5acc872a9d08d6632128fd9d757e1 100644 (file)
@@ -1413,11 +1413,11 @@ static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
        switch (stringset) {
        case ETH_SS_TEST:
                for (i = 0; i < IXGBE_TEST_LEN; i++)
-                       ethtool_sprintf(&p, ixgbe_gstrings_test[i]);
+                       ethtool_sprintf(&p, "%s", ixgbe_gstrings_test[i]);
                break;
        case ETH_SS_STATS:
                for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
-                       ethtool_sprintf(&p,
+                       ethtool_sprintf(&p, "%s",
                                        ixgbe_gstrings_stats[i].stat_string);
                for (i = 0; i < netdev->num_tx_queues; i++) {
                        ethtool_sprintf(&p, "tx_queue_%u_packets", i);