Skip to contentSkip to conversation

cleanup cppcheck warnings for fm10k driver

PATCH New Jacob Keller 2 participants 39 messages Jul 8, 2019 – Jul 12, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover cleanup cppcheck warnings for fm10k driver

This series contains several patches which resolve various warnings generated by using the cppcheck tool on the fm10k driver source code.

The most comment fix is to reduce the scope of local variables where possible, and the first 10 patches fix issues like this.

The remaining 9 patches fix other issues found by the tool. Only one of the patches contains what is likely a bug fix. Specifically, the last patch in the series fixes a 64-bit register read issue where we failed to bitwise or the high and low registers together. As this is only in the reporting flow for fault detection, it is relatively minor.

This series does not fix all of the cppcheck warnings:

[fm10k_ethtool.c:332]: (style) Argument 'idx!=29' to function BUG_ON is always 0

This warning is due to the fact that we can't use BUILD_BUG_ON. cppcheck is smart enough to realize that the index will always be 29, and thus that BUG_ON will never be triggered.

[fm10k_mbx.c:335] -> [fm10k_mbx.c:356]: (style) Variable 'head' is reassigned a value before the old one has been used. [fm10k_mbx.c:350] -> [fm10k_mbx.c:356]: (style) Variable 'head' is reassigned a value before the old one has been used. [fm10k_mbx.c:428] -> [fm10k_mbx.c:442]: (style) Variable 'tail' is reassigned a value before the old one has been used. [fm10k_mbx.c:439] -> [fm10k_mbx.c:442]: (style) Variable 'tail' is reassigned a value before the old one has been used.

These are almost certainly due to a bug in cppcheck analysis. The head and tail values are assigned initially outside the loop. Then, they're updated in the for loop. However, they aren't updated until the end of the *first* for-loop iteration. I think cppcheck doesn't understand this and thus assumes that the value will be overwritten before its first use.

Jacob Keller (19):
fm10k: reduce scope of the err variable
fm10k: reduce scope of *p local variable
fm10k: reduce the scope of qv local variable
fm10k: reduce the scope of local err variable
fm10k: reduce the scope of the q_idx local variable
fm10k: reduce the scope of the tx_buffer variable
fm10k: reduce the scope of the err variable
fm10k: reduce the scope of the local i variable
fm10k: reduce the scope of the local msg variable
fm10k: reduce the scope of the result local variable
fm10k: reduce scope of the ring variable
fm10k: remove unnecessary variable initializer
fm10k: remove needless assignment of err local variable
fm10k: remove needless initialization of size local variable
fm10k: explicitly return 0 on success path in function
fm10k: cast page_addr to u8 * when incrementing it
fm10k: mark unused parameters with __always_unused
fm10k: convert NON_Q_VECTORS(hw) into NON_Q_VECTORS
fm10k: fix fm10k_get_fault_pf to read correct address

 drivers/net/ethernet/intel/fm10k/fm10k.h      | 10 +++-----
 .../net/ethernet/intel/fm10k/fm10k_dcbnl.c    |  6 ++---
 .../net/ethernet/intel/fm10k/fm10k_ethtool.c  | 15 +++++------
 drivers/net/ethernet/intel/fm10k/fm10k_iov.c  |  5 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 15 +++++------
 drivers/net/ethernet/intel/fm10k/fm10k_mbx.c  | 11 +++++---
 .../net/ethernet/intel/fm10k/fm10k_netdev.c   | 20 +++++++--------
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c  | 20 +++++++--------
 drivers/net/ethernet/intel/fm10k/fm10k_pf.c   | 15 ++++++-----
 drivers/net/ethernet/intel/fm10k/fm10k_tlv.c  |  9 ++++---
 drivers/net/ethernet/intel/fm10k/fm10k_type.h |  2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_vf.c   | 25 +++++++++++--------
 12 files changed, 78 insertions(+), 75 deletions(-)
Signature · 1 line
2.22.0.214.g8dca754b1e87
#1 lore raw

PATCH 1/19 fm10k: reduce scope of the err variable

Reduce the scope of the err local variable in the fm10k_dcbnl_ieee_setets function.

This was detected using cppcheck, and resolves the following style warning:

[fm10k_dcbnl.c:37]: (style) The scope of the variable 'err' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_dcbnl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_dcbnl.c +3 -3
index 20768ac7f17e..c45315472245 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include "fm10k.h"
 
@@ -36,7 +36,7 @@ static int fm10k_dcbnl_ieee_getets(struct net_device *dev, struct ieee_ets *ets)
 static int fm10k_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
 {
 	u8 num_tc = 0;
-	int i, err;
+	int i;
 
 	/* verify type and determine num_tcs needed */
 	for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
@@ -57,7 +57,7 @@ static int fm10k_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
 
 	/* update TC hardware mapping if necessary */
 	if (num_tc != netdev_get_num_tc(dev)) {
-		err = fm10k_setup_tc(dev, num_tc);
+		int err = fm10k_setup_tc(dev, num_tc);
 		if (err)
 			return err;
 	}
Signature · 1 line
2.22.0.214.g8dca754b1e87
#2 lore raw

PATCH 1/19 fm10k: reduce scope of the err variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 01/19] fm10k: reduce scope of the err variable

Reduce the scope of the err local variable in the fm10k_dcbnl_ieee_setets function.

This was detected using cppcheck, and resolves the following style warning:

Quoted 6 lines

[fm10k_dcbnl.c:37]: (style) The scope of the variable 'err' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_dcbnl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
#3 lore raw

PATCH 2/19 fm10k: reduce scope of *p local variable

In reply to Jacob Keller

Reduce the scope of the char *p local variable to only the block where it is used.

This was detected by cppcheck and resolves the following style warning produced by that tool:

[fm10k_ethtool.c:229]: (style) The scope of the variable 'p' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +2 -3
index 4895dd83dd08..7b9440c0aee1 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include <linux/vmalloc.h>
 
@@ -222,7 +222,6 @@ static void __fm10k_add_ethtool_stats(u64 **data, void *pointer,
 				      const unsigned int size)
 {
 	unsigned int i;
-	char *p;
 
 	if (!pointer) {
 		/* memory is not zero allocated so we have to clear it */
@@ -232,7 +231,7 @@ static void __fm10k_add_ethtool_stats(u64 **data, void *pointer,
 	}
 
 	for (i = 0; i < size; i++) {
-		p = (char *)pointer + stats[i].stat_offset;
+		char *p = (char *)pointer + stats[i].stat_offset;
 
 		switch (stats[i].sizeof_stat) {
 		case sizeof(u64):
Signature · 1 line
2.22.0.214.g8dca754b1e87
#4 lore raw

PATCH 2/19 fm10k: reduce scope of *p local variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 02/19] fm10k: reduce scope of *p local variable

Reduce the scope of the char *p local variable to only the block where it is used.

This was detected by cppcheck and resolves the following style warning produced by that tool:

Quoted 6 lines

[fm10k_ethtool.c:229]: (style) The scope of the variable 'p' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
#5 lore raw

PATCH 3/19 fm10k: reduce the scope of qv local variable

In reply to Jacob Keller

Reduce the scope of the qv vector pointer local variable in the fm10k_set_coalesce function.

This was detected by cppcheck and resolves the following style warning produced by that tool:

[fm10k_ethtool.c:658]: (style) The scope of the variable 'qv' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +2 -2
index 7b9440c0aee1..1f7e4a8f4557 100644
@@ -650,7 +650,6 @@ static int fm10k_set_coalesce(struct net_device *dev,
 			      struct ethtool_coalesce *ec)
 {
 	struct fm10k_intfc *interface = netdev_priv(dev);
-	struct fm10k_q_vector *qv;
 	u16 tx_itr, rx_itr;
 	int i;
 
@@ -676,7 +675,8 @@ static int fm10k_set_coalesce(struct net_device *dev,
 
 	/* update q_vectors */
 	for (i = 0; i < interface->num_q_vectors; i++) {
-		qv = interface->q_vector[i];
+		struct fm10k_q_vector *qv = interface->q_vector[i];
+
 		qv->tx.itr = tx_itr;
 		qv->rx.itr = rx_itr;
 	}
Signature · 1 line
2.22.0.214.g8dca754b1e87
#6 lore raw

PATCH 3/19 fm10k: reduce the scope of qv local variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 03/19] fm10k: reduce the scope of qv local variable

Reduce the scope of the qv vector pointer local variable in the fm10k_set_coalesce function.

This was detected by cppcheck and resolves the following style warning produced by that tool:

Quoted 6 lines

[fm10k_ethtool.c:658]: (style) The scope of the variable 'qv' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#7 lore raw

PATCH 4/19 fm10k: reduce the scope of local err variable

In reply to Jacob Keller

Reduce the scope of the local err variable in the fm10k_iov_alloc_data function.

This was detected by cppcheck and resolves the following style warning produced by that tool:

[fm10k_iov.c:426]: (style) The scope of the variable 'err' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_iov.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_iov.c +3 -2
index 8de77155f2e7..afe1fafd2447 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include "fm10k.h"
 #include "fm10k_vf.h"
@@ -426,7 +426,7 @@ static s32 fm10k_iov_alloc_data(struct pci_dev *pdev, int num_vfs)
 	struct fm10k_iov_data *iov_data = interface->iov_data;
 	struct fm10k_hw *hw = &interface->hw;
 	size_t size;
-	int i, err;
+	int i;
 
 	/* return error if iov_data is already populated */
 	if (iov_data)
@@ -452,6 +452,7 @@ static s32 fm10k_iov_alloc_data(struct pci_dev *pdev, int num_vfs)
 	/* loop through vf_info structures initializing each entry */
 	for (i = 0; i < num_vfs; i++) {
 		struct fm10k_vf_info *vf_info = &iov_data->vf_info[i];
+		int err;
 
 		/* Record VF VSI value */
 		vf_info->vsi = i + 1;
Signature · 1 line
2.22.0.214.g8dca754b1e87
#8 lore raw

PATCH 4/19 fm10k: reduce the scope of local err variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 04/19] fm10k: reduce the scope of local err variable

Reduce the scope of the local err variable in the fm10k_iov_alloc_data function.

This was detected by cppcheck and resolves the following style warning produced by that tool:

Quoted 6 lines

[fm10k_iov.c:426]: (style) The scope of the variable 'err' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_iov.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
#9 lore raw

PATCH 5/19 fm10k: reduce the scope of the q_idx local variable

In reply to Jacob Keller

Reduce the scope of the q_idx local variable in the fm10k_cache_ring_qos function.

This was detected by cppcheck and resolves the following style warning produced by that tool:

[fm10k_main.c:2016]: (style) The scope of the variable 'q_idx' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_main.c +5 -4
index 90270b4a1682..3bacf35fbfad 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include <linux/types.h>
 #include <linux/module.h>
@@ -17,7 +17,7 @@ const char fm10k_driver_version[] = DRV_VERSION;
 char fm10k_driver_name[] = "fm10k";
 static const char fm10k_driver_string[] = DRV_SUMMARY;
 static const char fm10k_copyright[] =
-	"Copyright(c) 2013 - 2018 Intel Corporation.";
+	"Copyright(c) 2013 - 2019 Intel Corporation.";
 
 MODULE_AUTHOR("Intel Corporation, <[email protected]>");
 MODULE_DESCRIPTION(DRV_SUMMARY);
@@ -1869,7 +1869,7 @@ static int fm10k_init_msix_capability(struct fm10k_intfc *interface)
 static bool fm10k_cache_ring_qos(struct fm10k_intfc *interface)
 {
 	struct net_device *dev = interface->netdev;
-	int pc, offset, rss_i, i, q_idx;
+	int pc, offset, rss_i, i;
 	u16 pc_stride = interface->ring_feature[RING_F_QOS].mask + 1;
 	u8 num_pcs = netdev_get_num_tc(dev);
 
@@ -1879,7 +1879,8 @@ static bool fm10k_cache_ring_qos(struct fm10k_intfc *interface)
 	rss_i = interface->ring_feature[RING_F_RSS].indices;
 
 	for (pc = 0, offset = 0; pc < num_pcs; pc++, offset += rss_i) {
-		q_idx = pc;
+		int q_idx = pc;
+
 		for (i = 0; i < rss_i; i++) {
 			interface->tx_ring[offset + i]->reg_idx = q_idx;
 			interface->tx_ring[offset + i]->qos_pc = pc;
Signature · 1 line
2.22.0.214.g8dca754b1e87
#10 lore raw

PATCH 5/19 fm10k: reduce the scope of the q_idx local variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 05/19] fm10k: reduce the scope of the q_idx local variable

Reduce the scope of the q_idx local variable in the fm10k_cache_ring_qos function.

This was detected by cppcheck and resolves the following style warning produced by that tool:

Quoted 7 lines

[fm10k_main.c:2016]: (style) The scope of the variable 'q_idx' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
#11 lore raw

PATCH 6/19 fm10k: reduce the scope of the tx_buffer variable

In reply to Jacob Keller

The tx_buffer local variable in the function fm10k_clean_tx_ring is not used except inside a smaller block scope. Reduce the scope to its point of use.

This was detected by cppcheck and resolves the following style warning produced by that tool:

[fm10k_netdev.c:179]: (style) The scope of the variable 'tx_buffer' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +2 -2
index 538a8467f434..c73fb38be678 100644
@@ -169,7 +169,6 @@ void fm10k_unmap_and_free_tx_resource(struct fm10k_ring *ring,
  **/
 static void fm10k_clean_tx_ring(struct fm10k_ring *tx_ring)
 {
-	struct fm10k_tx_buffer *tx_buffer;
 	unsigned long size;
 	u16 i;
 
@@ -179,7 +178,8 @@ static void fm10k_clean_tx_ring(struct fm10k_ring *tx_ring)
 
 	/* Free all the Tx ring sk_buffs */
 	for (i = 0; i < tx_ring->count; i++) {
-		tx_buffer = &tx_ring->tx_buffer[i];
+		struct fm10k_tx_buffer *tx_buffer = &tx_ring->tx_buffer[i];
+
 		fm10k_unmap_and_free_tx_resource(tx_ring, tx_buffer);
 	}
 
Signature · 1 line
2.22.0.214.g8dca754b1e87
#12 lore raw

PATCH 6/19 fm10k: reduce the scope of the tx_buffer variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 06/19] fm10k: reduce the scope of the tx_buffer variable

The tx_buffer local variable in the function fm10k_clean_tx_ring is not used except inside a smaller block scope. Reduce the scope to its point of use.

This was detected by cppcheck and resolves the following style warning produced by that tool:

Quoted 7 lines

[fm10k_netdev.c:179]: (style) The scope of the variable 'tx_buffer' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#13 lore raw

PATCH 7/19 fm10k: reduce the scope of the err variable

In reply to Jacob Keller

Reduce the scope of the local variable err in the fm10k_detach_subtask function.

This was detected by cppcheck and resolves the following warning produced by that tool:

[fm10k_pci.c:403]: (style) The scope of the variable 'err' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +3 -2
index e49fb51d3613..8cdfb24125bf 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include <linux/module.h>
 #include <linux/interrupt.h>
@@ -344,7 +344,6 @@ static void fm10k_detach_subtask(struct fm10k_intfc *interface)
 	struct net_device *netdev = interface->netdev;
 	u32 __iomem *hw_addr;
 	u32 value;
-	int err;
 
 	/* do nothing if netdev is still present or hw_addr is set */
 	if (netif_device_present(netdev) || interface->hw.hw_addr)
@@ -362,6 +361,8 @@ static void fm10k_detach_subtask(struct fm10k_intfc *interface)
 	hw_addr = READ_ONCE(interface->uc_addr);
 	value = readl(hw_addr);
 	if (~value) {
+		int err;
+
 		/* Make sure the reset was initiated because we detached,
 		 * otherwise we might race with a different reset flow.
 		 */
Signature · 1 line
2.22.0.214.g8dca754b1e87
#14 lore raw

PATCH 7/19 fm10k: reduce the scope of the err variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 07/19] fm10k: reduce the scope of the err variable

Reduce the scope of the local variable err in the fm10k_detach_subtask function.

This was detected by cppcheck and resolves the following warning produced by that tool:

Quoted 6 lines

[fm10k_pci.c:403]: (style) The scope of the variable 'err' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
#15 lore raw

PATCH 8/19 fm10k: reduce the scope of the local i variable

In reply to Jacob Keller

Reduce the scope of the local loop variable in the fm10k_check_hang_subtask function.

This was detected by cppcheck and resolves the following warning produced by that tool:

[driver/fm10k_pci.c:852]: (style) The scope of the variable 'i' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +2 -2
index 8cdfb24125bf..10a3b2576a3c 100644
@@ -698,8 +698,6 @@ static void fm10k_watchdog_subtask(struct fm10k_intfc *interface)
  */
 static void fm10k_check_hang_subtask(struct fm10k_intfc *interface)
 {
-	int i;
-
 	/* If we're down or resetting, just bail */
 	if (test_bit(__FM10K_DOWN, interface->state) ||
 	    test_bit(__FM10K_RESETTING, interface->state))
@@ -711,6 +709,8 @@ static void fm10k_check_hang_subtask(struct fm10k_intfc *interface)
 	interface->next_tx_hang_check = jiffies + (2 * HZ);
 
 	if (netif_carrier_ok(interface->netdev)) {
+		int i;
+
 		/* Force detection of hung controller */
 		for (i = 0; i < interface->num_tx_queues; i++)
 			set_check_for_tx_hang(interface->tx_ring[i]);
Signature · 1 line
2.22.0.214.g8dca754b1e87
#16 lore raw

PATCH 8/19 fm10k: reduce the scope of the local i variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 08/19] fm10k: reduce the scope of the local i variable

Reduce the scope of the local loop variable in the fm10k_check_hang_subtask function.

This was detected by cppcheck and resolves the following warning produced by that tool:

Quoted 6 lines

[driver/fm10k_pci.c:852]: (style) The scope of the variable 'i' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#17 lore raw

PATCH 9/19 fm10k: reduce the scope of the local msg variable

In reply to Jacob Keller

The msg variable in the fm10k_mbx_validate_msg_size and fm10k_sm_mbx_transmit functions is only used within the do {} loop scope. Reduce its scope only to where it is used.

This was detected by cppcheck, and resolves the following warnings produced by that tool:

[fm10k_mbx.c:299]: (style) The scope of the variable 'msg' can be reduced. [fm10k_mbx.c:2004]: (style) The scope of the variable 'msg' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_mbx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_mbx.c +4 -2
index 21021fe4f1c3..aece335b41f8 100644
@@ -297,13 +297,14 @@ static u16 fm10k_mbx_validate_msg_size(struct fm10k_mbx_info *mbx, u16 len)
 {
 	struct fm10k_mbx_fifo *fifo = &mbx->rx;
 	u16 total_len = 0, msg_len;
-	u32 *msg;
 
 	/* length should include previous amounts pushed */
 	len += mbx->pushed;
 
 	/* offset in message is based off of current message size */
 	do {
+		u32 *msg;
+
 		msg = fifo->buffer + fm10k_fifo_tail_offset(fifo, total_len);
 		msg_len = FM10K_TLV_DWORD_LEN(*msg);
 		total_len += msg_len;
@@ -1920,7 +1921,6 @@ static void fm10k_sm_mbx_transmit(struct fm10k_hw *hw,
 	/* reduce length by 1 to convert to a mask */
 	u16 mbmem_len = mbx->mbmem_len - 1;
 	u16 tail_len, len = 0;
-	u32 *msg;
 
 	/* push head behind tail */
 	if (mbx->tail < head)
@@ -1930,6 +1930,8 @@ static void fm10k_sm_mbx_transmit(struct fm10k_hw *hw,
 
 	/* determine msg aligned offset for end of buffer */
 	do {
+		u32 *msg;
+
 		msg = fifo->buffer + fm10k_fifo_head_offset(fifo, len);
 		tail_len = len;
 		len += FM10K_TLV_DWORD_LEN(*msg);
Signature · 1 line
2.22.0.214.g8dca754b1e87
#18 lore raw

PATCH 9/19 fm10k: reduce the scope of the local msg variable

Quoted 15 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 09/19] fm10k: reduce the scope of the local msg variable

The msg variable in the fm10k_mbx_validate_msg_size and fm10k_sm_mbx_transmit functions is only used within the do {} loop scope. Reduce its scope only to where it is used.

This was detected by cppcheck, and resolves the following warnings produced by that tool:

Quoted 7 lines

[fm10k_mbx.c:299]: (style) The scope of the variable 'msg' can be reduced. [fm10k_mbx.c:2004]: (style) The scope of the variable 'msg' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_mbx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
#19 lore raw

PATCH 10/19 fm10k: reduce the scope of the result local variable

In reply to Jacob Keller

Reduce the scope of the result local variable in the fm10k_iov_msg_lport_state_pf function.

This was detected by cppcheck and resolves the following warning produced by that tool:

[fm10k_pf.c:1435]: (style) The scope of the variable 'result' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_pf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pf.c +1 -2
index cb4d02629b86..e85b2f2eef05 100644
@@ -1352,7 +1352,6 @@ s32 fm10k_iov_msg_lport_state_pf(struct fm10k_hw *hw, u32 **results,
 				 struct fm10k_mbx_info *mbx)
 {
 	struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
-	u32 *result;
 	s32 err = 0;
 	u32 msg[2];
 	u8 mode = 0;
@@ -1362,7 +1361,7 @@ s32 fm10k_iov_msg_lport_state_pf(struct fm10k_hw *hw, u32 **results,
 		return FM10K_ERR_PARAM;
 
 	if (!!results[FM10K_LPORT_STATE_MSG_XCAST_MODE]) {
-		result = results[FM10K_LPORT_STATE_MSG_XCAST_MODE];
+		u32 *result = results[FM10K_LPORT_STATE_MSG_XCAST_MODE];
 
 		/* XCAST mode update requested */
 		err = fm10k_tlv_attr_get_u8(result, &mode);
Signature · 1 line
2.22.0.214.g8dca754b1e87
#20 lore raw

PATCH 10/19 fm10k: reduce the scope of the result local variable

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 10/19] fm10k: reduce the scope of the result local variable

Reduce the scope of the result local variable in the fm10k_iov_msg_lport_state_pf function.

This was detected by cppcheck and resolves the following warning produced by that tool:

Quoted 6 lines

[fm10k_pf.c:1435]: (style) The scope of the variable 'result' can be reduced.

---
 drivers/net/ethernet/intel/fm10k/fm10k_pf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
#21 lore raw

PATCH 11/19 fm10k: reduce scope of the ring variable

In reply to Jacob Keller

Reduce the scope of the ring local variable in the fm10k_assign_l2_accel function.

This was detected by cppcheck and resolves the following warning produced by that tool:

[fm10k_netdev.c:1447]: (style) The scope of the variable 'ring' can be reduced.

Change-Id Ia2f2bc0cabed02c65f513e9917bc1859d5cc414c

Title: fm10k: reduce scope of the ring variable
Change-type: ImplementationChange

---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +2 -2
index c73fb38be678..259da075093f 100644
@@ -1444,11 +1444,11 @@ static int __fm10k_setup_tc(struct net_device *dev, enum tc_setup_type type,
 static void fm10k_assign_l2_accel(struct fm10k_intfc *interface,
 				  struct fm10k_l2_accel *l2_accel)
 {
-	struct fm10k_ring *ring;
 	int i;
 
 	for (i = 0; i < interface->num_rx_queues; i++) {
-		ring = interface->rx_ring[i];
+		struct fm10k_ring *ring = interface->rx_ring[i];
+
 		rcu_assign_pointer(ring->l2_accel, l2_accel);
 	}
 
Signature · 1 line
2.22.0.214.g8dca754b1e87
#22 lore raw

PATCH 11/19 fm10k: reduce scope of the ring variable

Quoted 17 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 11/19] fm10k: reduce scope of the ring variable

Reduce the scope of the ring local variable in the fm10k_assign_l2_accel function.

This was detected by cppcheck and resolves the following warning produced by that tool:

[fm10k_netdev.c:1447]: (style) The scope of the variable 'ring' can be reduced.

Quoted 7 lines
Change-Id Ia2f2bc0cabed02c65f513e9917bc1859d5cc414c

Title: fm10k: reduce scope of the ring variable
Change-type: ImplementationChange

---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#23 lore raw

PATCH 12/19 fm10k: remove unnecessary variable initializer

In reply to Jacob Keller

The err variable in the fm10k_tlv_attr_parse function is initialized with zero. However, the function never reads err without first assigning it from a function call. Remove this unnecessary initialization.

This was detected by cppcheck and resolves the following warning produced by that tool:

[fm10k_tlv.c:498]: (style) Variable 'err' is assigned a value that is never used.

---
 drivers/net/ethernet/intel/fm10k/fm10k_tlv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_tlv.c +1 -1
index 2a7a40bf2b1c..f4c42a40f934 100644
@@ -472,7 +472,7 @@ static s32 fm10k_tlv_attr_parse(u32 *attr, u32 **results,
 				const struct fm10k_tlv_attr *tlv_attr)
 {
 	u32 i, attr_id, offset = 0;
-	s32 err = 0;
+	s32 err;
 	u16 len;
 
 	/* verify pointers are not NULL */
Signature · 1 line
2.22.0.214.g8dca754b1e87
#24 lore raw

PATCH 12/19 fm10k: remove unnecessary variable initializer

Quoted 15 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:12 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 12/19] fm10k: remove unnecessary variable initializer

The err variable in the fm10k_tlv_attr_parse function is initialized with zero. However, the function never reads err without first assigning it from a function call. Remove this unnecessary initialization.

This was detected by cppcheck and resolves the following warning produced by that tool:

Quoted 6 lines

[fm10k_tlv.c:498]: (style) Variable 'err' is assigned a value that is never used.

---
 drivers/net/ethernet/intel/fm10k/fm10k_tlv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#25 lore raw

PATCH 13/19 fm10k: remove needless assignment of err local variable

In reply to Jacob Keller

The local variable err in several functions in the fm10k_netdev.c file is initialized with a value that is never used. The err value is immediately re-assigned in all cases where it will be checked. Remove the unnecessary initializers.

This was detected by cppcheck and resolves the following warnings produced by that tool:

[fm10k_netdev.c:999] -> [fm10k_netdev.c:1004]: (style) Variable 'err' is reassigned a value before the old one has been used.

[fm10k_netdev.c:1019] -> [fm10k_netdev.c:1024]: (style) Variable 'err' is reassigned a value before the old one has been used.

[fm10k_netdev.c:64]: (style) Variable 'err' is assigned a value that is never used.

[fm10k_netdev.c:131]: (style) Variable 'err' is assigned a value that is never used.

---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +5 -5
index 259da075093f..4704395c0f66 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include "fm10k.h"
 #include <linux/vmalloc.h>
@@ -54,7 +54,7 @@ int fm10k_setup_tx_resources(struct fm10k_ring *tx_ring)
  **/
 static int fm10k_setup_all_tx_resources(struct fm10k_intfc *interface)
 {
-	int i, err = 0;
+	int i, err;
 
 	for (i = 0; i < interface->num_tx_queues; i++) {
 		err = fm10k_setup_tx_resources(interface->tx_ring[i]);
@@ -121,7 +121,7 @@ int fm10k_setup_rx_resources(struct fm10k_ring *rx_ring)
  **/
 static int fm10k_setup_all_rx_resources(struct fm10k_intfc *interface)
 {
-	int i, err = 0;
+	int i, err;
 
 	for (i = 0; i < interface->num_rx_queues; i++) {
 		err = fm10k_setup_rx_resources(interface->rx_ring[i]);
@@ -871,7 +871,7 @@ static int fm10k_uc_vlan_unsync(struct net_device *netdev,
 	u16 glort = interface->glort;
 	u16 vid = interface->vid;
 	bool set = !!(vid / VLAN_N_VID);
-	int err = -EHOSTDOWN;
+	int err;
 
 	/* drop any leading bits on the VLAN ID */
 	vid &= VLAN_N_VID - 1;
@@ -891,7 +891,7 @@ static int fm10k_mc_vlan_unsync(struct net_device *netdev,
 	u16 glort = interface->glort;
 	u16 vid = interface->vid;
 	bool set = !!(vid / VLAN_N_VID);
-	int err = -EHOSTDOWN;
+	int err;
 
 	/* drop any leading bits on the VLAN ID */
 	vid &= VLAN_N_VID - 1;
Signature · 1 line
2.22.0.214.g8dca754b1e87
#26 lore raw

PATCH 13/19 fm10k: remove needless assignment of err local variable

Quoted 25 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:13 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 13/19] fm10k: remove needless assignment of err local variable

The local variable err in several functions in the fm10k_netdev.c file is initialized with a value that is never used. The err value is immediately re- assigned in all cases where it will be checked. Remove the unnecessary initializers.

This was detected by cppcheck and resolves the following warnings produced by that tool:

[fm10k_netdev.c:999] -> [fm10k_netdev.c:1004]: (style) Variable 'err' is reassigned a value before the old one has been used.

[fm10k_netdev.c:1019] -> [fm10k_netdev.c:1024]: (style) Variable 'err' is reassigned a value before the old one has been used.

[fm10k_netdev.c:64]: (style) Variable 'err' is assigned a value that is never used.

Quoted 7 lines

[fm10k_netdev.c:131]: (style) Variable 'err' is assigned a value that is never used.

---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
#27 lore raw

PATCH 14/19 fm10k: remove needless initialization of size local variable

In reply to Jacob Keller

The local variable 'size' in fm10k_dfwd_add_station is initialized, but is always re-assigned immediately before use. Remove this unnecessary initialization.

This was detected by cppcheck and resolves the following warning produced by that tool:

[fm10k_netdev.c:1466]: (style) Variable 'size' is assigned a value that is never used.

Change-Id I6f6d1ba3b9b26c2ed6f434fbeeafbbda4b78db33

Title: fm10k: remove needless initialization of size local variable
Change-type: ImplementationChange

---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +1 -1
index 4704395c0f66..d3e85480f46d 100644
@@ -1463,7 +1463,7 @@ static void *fm10k_dfwd_add_station(struct net_device *dev,
 	struct fm10k_l2_accel *old_l2_accel = NULL;
 	struct fm10k_dglort_cfg dglort = { 0 };
 	struct fm10k_hw *hw = &interface->hw;
-	int size = 0, i;
+	int size, i;
 	u16 vid, glort;
 
 	/* The hardware supported by fm10k only filters on the destination MAC
Signature · 1 line
2.22.0.214.g8dca754b1e87
#28 lore raw

PATCH 14/19 fm10k: remove needless initialization of size local variable

Quoted 17 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:13 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 14/19] fm10k: remove needless initialization of size local variable

The local variable 'size' in fm10k_dfwd_add_station is initialized, but is always re-assigned immediately before use. Remove this unnecessary initialization.

This was detected by cppcheck and resolves the following warning produced by that tool:

[fm10k_netdev.c:1466]: (style) Variable 'size' is assigned a value that is never used.

Quoted 7 lines
Change-Id I6f6d1ba3b9b26c2ed6f434fbeeafbbda4b78db33

Title: fm10k: remove needless initialization of size local variable
Change-type: ImplementationChange

---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#29 lore raw

PATCH 15/19 fm10k: explicitly return 0 on success path in function

In reply to Jacob Keller

In the fm10k_handle_resume function, return 0 explicitly at the end of the function instead of returning the err value.

This was detected by cppcheck and resolves the following style warning produced by that tool:

[fm10k_pci.c:2768] -> [fm10k_pci.c:2787]: (warning) Identical condition 'err', second condition is always false

---
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +1 -1
index 10a3b2576a3c..082e68354643 100644
@@ -2340,7 +2340,7 @@ static int fm10k_handle_resume(struct fm10k_intfc *interface)
 	/* Restart the MAC/VLAN request queue in-case of outstanding events */
 	fm10k_macvlan_schedule(interface);
 
-	return err;
+	return 0;
 }
 
 /**
Signature · 1 line
2.22.0.214.g8dca754b1e87
#30 lore raw

PATCH 15/19 fm10k: explicitly return 0 on success path in function

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:13 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 15/19] fm10k: explicitly return 0 on success path in function

In the fm10k_handle_resume function, return 0 explicitly at the end of the function instead of returning the err value.

This was detected by cppcheck and resolves the following style warning produced by that tool:

Quoted 7 lines

[fm10k_pci.c:2768] -> [fm10k_pci.c:2787]: (warning) Identical condition 'err', second condition is always false

---
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#31 lore raw

PATCH 16/19 fm10k: cast page_addr to u8 * when incrementing it

In reply to Jacob Keller

The page_addr variable is a void pointer. Incrementing it before calling prefetch is technically undefined. Fix this by casting it to a u8* pointer before incrementing it. This ensures that we increment the pointer value in byte units, instead of relying on this undefined behavior.

This was detected by cppcheck, and resolves the following warning produced by that tool:

[fm10k_main.c:328]: (portability) 'page_addr' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.

---
 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_main.c +1 -1
index 3bacf35fbfad..cf87812bdf4a 100644
@@ -315,7 +315,7 @@ static struct sk_buff *fm10k_fetch_rx_buffer(struct fm10k_ring *rx_ring,
 		/* prefetch first cache line of first page */
 		prefetch(page_addr);
 #if L1_CACHE_BYTES < 128
-		prefetch(page_addr + L1_CACHE_BYTES);
+		prefetch((void *)((u8 *)page_addr + L1_CACHE_BYTES));
 #endif
 
 		/* allocate a skb to store the frags */
Signature · 1 line
2.22.0.214.g8dca754b1e87
#32 lore raw

PATCH 16/19 fm10k: cast page_addr to u8 * when incrementing it

Quoted 16 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:13 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 16/19] fm10k: cast page_addr to u8 * when incrementing it

The page_addr variable is a void pointer. Incrementing it before calling prefetch is technically undefined. Fix this by casting it to a u8* pointer before incrementing it. This ensures that we increment the pointer value in byte units, instead of relying on this undefined behavior.

This was detected by cppcheck, and resolves the following warning produced by that tool:

Quoted 7 lines

[fm10k_main.c:328]: (portability) 'page_addr' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.

---
 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#33 lore raw

PATCH 17/19 fm10k: mark unused parameters with __always_unused

In reply to Jacob Keller

Several functions in the fm10k driver have specific function templates, as they are used as function pointers. The parameters in these functions are not always used. Explicitly mark unused parameters with the __always_unused macro, so that the compiler will not warn about them when building with the -Wunused-parameter warning enabled.

---
 drivers/net/ethernet/intel/fm10k/fm10k_mbx.c  |  5 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_pf.c   | 10 ++++----
 drivers/net/ethernet/intel/fm10k/fm10k_tlv.c  |  7 +++---
 drivers/net/ethernet/intel/fm10k/fm10k_type.h |  2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_vf.c   | 25 +++++++++++--------
 5 files changed, 28 insertions(+), 21 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_mbx.c +3 -2
index aece335b41f8..75e51f91036c 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include "fm10k_common.h"
 
@@ -2134,7 +2134,8 @@ static s32 fm10k_sm_mbx_process(struct fm10k_hw *hw,
  *  DWORDs, not bytes.  Any invalid values will cause the mailbox to return
  *  error.
  **/
-s32 fm10k_sm_mbx_init(struct fm10k_hw *hw, struct fm10k_mbx_info *mbx,
+s32 fm10k_sm_mbx_init(struct fm10k_hw __always_unused *hw,
+		      struct fm10k_mbx_info *mbx,
 		      const struct fm10k_msg_data *msg_data)
 {
 	mbx->mbx_reg = FM10K_GMBX;
drivers/net/ethernet/intel/fm10k/fm10k_pf.c +5 -5
index e85b2f2eef05..095c5b0e4096 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include "fm10k_pf.h"
 #include "fm10k_vf.h"
@@ -1152,7 +1152,7 @@ static void fm10k_iov_update_stats_pf(struct fm10k_hw *hw,
  *  assumption is that in this case it is acceptable to just directly
  *  hand off the message from the VF to the underlying shared code.
  **/
-s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 **results,
+s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 __always_unused **results,
 			  struct fm10k_mbx_info *mbx)
 {
 	struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
@@ -1641,7 +1641,7 @@ const struct fm10k_tlv_attr fm10k_lport_map_msg_attr[] = {
  *  switch API.
  **/
 s32 fm10k_msg_lport_map_pf(struct fm10k_hw *hw, u32 **results,
-			   struct fm10k_mbx_info *mbx)
+			   struct fm10k_mbx_info __always_unused *mbx)
 {
 	u16 glort, mask;
 	u32 dglort_map;
@@ -1684,7 +1684,7 @@ const struct fm10k_tlv_attr fm10k_update_pvid_msg_attr[] = {
  *  This handler configures the default VLAN for the PF
  **/
 static s32 fm10k_msg_update_pvid_pf(struct fm10k_hw *hw, u32 **results,
-				    struct fm10k_mbx_info *mbx)
+				    struct fm10k_mbx_info __always_unused *mbx)
 {
 	u16 glort, pvid;
 	u32 pvid_update;
@@ -1745,7 +1745,7 @@ const struct fm10k_tlv_attr fm10k_err_msg_attr[] = {
  *  messages that the PF has sent.
  **/
 s32 fm10k_msg_err_pf(struct fm10k_hw *hw, u32 **results,
-		     struct fm10k_mbx_info *mbx)
+		     struct fm10k_mbx_info __always_unused *mbx)
 {
 	struct fm10k_swapi_error err_msg;
 	s32 err;
drivers/net/ethernet/intel/fm10k/fm10k_tlv.c +4 -3
index f4c42a40f934..21eff0895a7a 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include "fm10k_tlv.h"
 
@@ -587,8 +587,9 @@ s32 fm10k_tlv_msg_parse(struct fm10k_hw *hw, u32 *msg,
  *  a minimum it just indicates that the message requested was
  *  unimplemented.
  **/
-s32 fm10k_tlv_msg_error(struct fm10k_hw *hw, u32 **results,
-			struct fm10k_mbx_info *mbx)
+s32 fm10k_tlv_msg_error(struct fm10k_hw __always_unused *hw,
+			u32 __always_unused **results,
+			struct fm10k_mbx_info __always_unused *mbx)
 {
 	return FM10K_NOT_IMPLEMENTED;
 }
drivers/net/ethernet/intel/fm10k/fm10k_type.h +1 -1
index 9fb9fca375e3..15ac1c7885bc 100644
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #ifndef _FM10K_TYPE_H_
 #define _FM10K_TYPE_H_
drivers/net/ethernet/intel/fm10k/fm10k_vf.c +15 -10
index a8519c1f0406..dc8ccd378ec9 100644
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #include "fm10k_vf.h"
 
@@ -198,7 +198,7 @@ static s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
  *  This function should determine the MAC address for the VF
  **/
 s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
-			  struct fm10k_mbx_info *mbx)
+			  struct fm10k_mbx_info __always_unused *mbx)
 {
 	u8 perm_addr[ETH_ALEN];
 	u16 vid;
@@ -267,8 +267,10 @@ static s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
  *  This function is used to add or remove unicast MAC addresses for
  *  the VF.
  **/
-static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
-				   const u8 *mac, u16 vid, bool add, u8 flags)
+static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw,
+				   u16 __always_unused glort,
+				   const u8 *mac, u16 vid, bool add,
+				   u8 __always_unused flags)
 {
 	struct fm10k_mbx_info *mbx = &hw->mbx;
 	u32 msg[7];
@@ -309,7 +311,8 @@ static s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
  *  This function is used to add or remove multicast MAC addresses for
  *  the VF.
  **/
-static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
+static s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw,
+				   u16 __always_unused glort,
 				   const u8 *mac, u16 vid, bool add)
 {
 	struct fm10k_mbx_info *mbx = &hw->mbx;
@@ -373,7 +376,7 @@ const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
  *  are ready to bring up the interface.
  **/
 s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
-			     struct fm10k_mbx_info *mbx)
+			     struct fm10k_mbx_info __always_unused *mbx)
 {
 	hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
 			     FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
@@ -392,8 +395,9 @@ s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
  *  enabled we can add filters, if it is disabled all filters for this
  *  logical port are flushed.
  **/
-static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
-				       u16 count, bool enable)
+static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw,
+				       u16 __always_unused glort,
+				       u16 __always_unused count, bool enable)
 {
 	struct fm10k_mbx_info *mbx = &hw->mbx;
 	u32 msg[2];
@@ -420,7 +424,8 @@ static s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
  *  so that it can enable either multicast, multicast promiscuous, or
  *  promiscuous mode of operation.
  **/
-static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
+static s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw,
+				      u16 __always_unused glort, u8 mode)
 {
 	struct fm10k_mbx_info *mbx = &hw->mbx;
 	u32 msg[3];
@@ -475,7 +480,7 @@ static void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
  *  that information to then populate a DGLORTMAP/DEC entry and the queues
  *  to which it has been assigned.
  **/
-static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
+static s32 fm10k_configure_dglort_map_vf(struct fm10k_hw __always_unused *hw,
 					 struct fm10k_dglort_cfg *dglort)
 {
 	/* verify the dglort pointer */
Signature · 1 line
2.22.0.214.g8dca754b1e87
#34 lore raw

PATCH 17/19 fm10k: mark unused parameters with __always_unused

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:13 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 17/19] fm10k: mark unused parameters with __always_unused

Several functions in the fm10k driver have specific function templates, as they are used as function pointers. The parameters in these functions are not always used. Explicitly mark unused parameters with the __always_unused macro, so that the compiler will not warn about them when building with the -Wunused-parameter warning enabled.

Quoted 8 lines
---
 drivers/net/ethernet/intel/fm10k/fm10k_mbx.c  |  5 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_pf.c   | 10 ++++----
 drivers/net/ethernet/intel/fm10k/fm10k_tlv.c  |  7 +++---
drivers/net/ethernet/intel/fm10k/fm10k_type.h |  2 +-
 drivers/net/ethernet/intel/fm10k/fm10k_vf.c   | 25 +++++++++++--------
 5 files changed, 28 insertions(+), 21 deletions(-)
#35 lore raw

PATCH 18/19 fm10k: convert NON_Q_VECTORS(hw) into NON_Q_VECTORS

In reply to Jacob Keller

The driver currently uses a macro to decide whether we should use NON_Q_VECTORS_PF or NON_Q_VECTORS_VF.

However, we also define NON_Q_VECTORS_VF to the same value as NON_Q_VECTORS_PF. This means that the macro NON_Q_VECTORS(hw) will always return the same value.

Let's just remove this macro, and replace it directly with an enum value on the enum non_q_vectors.

This was detected by cppcheck and fixes the following warnings when building with BUILD=KERNEL

[fm10k_ethtool.c:1123]: (style) Same value in both branches of ternary operator.

[fm10k_ethtool.c:1142]: (style) Same value in both branches of ternary operator.

[fm10k_main.c:1826]: (style) Same value in both branches of ternary operator.

[fm10k_main.c:1849]: (style) Same value in both branches of ternary operator.

[fm10k_main.c:1858]: (style) Same value in both branches of ternary operator.

[fm10k_pci.c:901]: (style) Same value in both branches of ternary operator.

[fm10k_pci.c:1040]: (style) Same value in both branches of ternary operator.

[fm10k_pci.c:1726]: (style) Same value in both branches of ternary operator.

[fm10k_pci.c:1763]: (style) Same value in both branches of ternary operator.

---
 drivers/net/ethernet/intel/fm10k/fm10k.h         | 10 +++-------
 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c |  6 ++----
 drivers/net/ethernet/intel/fm10k/fm10k_main.c    |  4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c     |  9 ++++-----
 4 files changed, 11 insertions(+), 18 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k.h +3 -7
index 7d42582ed48d..b14441944b4b 100644
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-/* Copyright(c) 2013 - 2018 Intel Corporation. */
+/* Copyright(c) 2013 - 2019 Intel Corporation. */
 
 #ifndef _FM10K_H_
 #define _FM10K_H_
@@ -177,14 +177,10 @@ static inline struct netdev_queue *txring_txq(const struct fm10k_ring *ring)
 #define MIN_Q_VECTORS	1
 enum fm10k_non_q_vectors {
 	FM10K_MBX_VECTOR,
-#define NON_Q_VECTORS_VF NON_Q_VECTORS_PF
-	NON_Q_VECTORS_PF
+	NON_Q_VECTORS
 };
 
-#define NON_Q_VECTORS(hw)	(((hw)->mac.type == fm10k_mac_pf) ? \
-						NON_Q_VECTORS_PF : \
-						NON_Q_VECTORS_VF)
-#define MIN_MSIX_COUNT(hw)	(MIN_Q_VECTORS + NON_Q_VECTORS(hw))
+#define MIN_MSIX_COUNT(hw)	(MIN_Q_VECTORS + NON_Q_VECTORS)
 
 struct fm10k_q_vector {
 	struct fm10k_intfc *interface;
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +2 -4
index 1f7e4a8f4557..c681d2d28107 100644
@@ -1114,13 +1114,12 @@ static void fm10k_get_channels(struct net_device *dev,
 			       struct ethtool_channels *ch)
 {
 	struct fm10k_intfc *interface = netdev_priv(dev);
-	struct fm10k_hw *hw = &interface->hw;
 
 	/* report maximum channels */
 	ch->max_combined = fm10k_max_channels(dev);
 
 	/* report info for other vector */
-	ch->max_other = NON_Q_VECTORS(hw);
+	ch->max_other = NON_Q_VECTORS;
 	ch->other_count = ch->max_other;
 
 	/* record RSS queues */
@@ -1132,14 +1131,13 @@ static int fm10k_set_channels(struct net_device *dev,
 {
 	struct fm10k_intfc *interface = netdev_priv(dev);
 	unsigned int count = ch->combined_count;
-	struct fm10k_hw *hw = &interface->hw;
 
 	/* verify they are not requesting separate vectors */
 	if (!count || ch->rx_count || ch->tx_count)
 		return -EINVAL;
 
 	/* verify other_count has not changed */
-	if (ch->other_count != NON_Q_VECTORS(hw))
+	if (ch->other_count != NON_Q_VECTORS)
 		return -EINVAL;
 
 	/* verify the number of channels does not exceed hardware limits */
drivers/net/ethernet/intel/fm10k/fm10k_main.c +2 -2
index cf87812bdf4a..701f83325c49 100644
@@ -1823,7 +1823,7 @@ static int fm10k_init_msix_capability(struct fm10k_intfc *interface)
 	v_budget = min_t(u16, v_budget, num_online_cpus());
 
 	/* account for vectors not related to queues */
-	v_budget += NON_Q_VECTORS(hw);
+	v_budget += NON_Q_VECTORS;
 
 	/* At the same time, hardware can only support a maximum of
 	 * hw.mac->max_msix_vectors vectors.  With features
@@ -1855,7 +1855,7 @@ static int fm10k_init_msix_capability(struct fm10k_intfc *interface)
 	}
 
 	/* record the number of queues available for q_vectors */
-	interface->num_q_vectors = v_budget - NON_Q_VECTORS(hw);
+	interface->num_q_vectors = v_budget - NON_Q_VECTORS;
 
 	return 0;
 }
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +4 -5
index 082e68354643..1dfa9eaea368 100644
@@ -898,7 +898,7 @@ static void fm10k_configure_tx_ring(struct fm10k_intfc *interface,
 
 	/* Map interrupt */
 	if (ring->q_vector) {
-		txint = ring->q_vector->v_idx + NON_Q_VECTORS(hw);
+		txint = ring->q_vector->v_idx + NON_Q_VECTORS;
 		txint |= FM10K_INT_MAP_TIMER0;
 	}
 
@@ -1037,7 +1037,7 @@ static void fm10k_configure_rx_ring(struct fm10k_intfc *interface,
 
 	/* Map interrupt */
 	if (ring->q_vector) {
-		rxint = ring->q_vector->v_idx + NON_Q_VECTORS(hw);
+		rxint = ring->q_vector->v_idx + NON_Q_VECTORS;
 		rxint |= FM10K_INT_MAP_TIMER1;
 	}
 
@@ -1720,10 +1720,9 @@ int fm10k_mbx_request_irq(struct fm10k_intfc *interface)
 void fm10k_qv_free_irq(struct fm10k_intfc *interface)
 {
 	int vector = interface->num_q_vectors;
-	struct fm10k_hw *hw = &interface->hw;
 	struct msix_entry *entry;
 
-	entry = &interface->msix_entries[NON_Q_VECTORS(hw) + vector];
+	entry = &interface->msix_entries[NON_Q_VECTORS + vector];
 
 	while (vector) {
 		struct fm10k_q_vector *q_vector;
@@ -1760,7 +1759,7 @@ int fm10k_qv_request_irq(struct fm10k_intfc *interface)
 	unsigned int ri = 0, ti = 0;
 	int vector, err;
 
-	entry = &interface->msix_entries[NON_Q_VECTORS(hw)];
+	entry = &interface->msix_entries[NON_Q_VECTORS];
 
 	for (vector = 0; vector < interface->num_q_vectors; vector++) {
 		struct fm10k_q_vector *q_vector = interface->q_vector[vector];
Signature · 1 line
2.22.0.214.g8dca754b1e87
#36 lore raw

PATCH 18/19 fm10k: convert NON_Q_VECTORS(hw) into NON_Q_VECTORS

Quoted 44 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:13 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 18/19] fm10k: convert NON_Q_VECTORS(hw) into NON_Q_VECTORS

The driver currently uses a macro to decide whether we should use NON_Q_VECTORS_PF or NON_Q_VECTORS_VF.

However, we also define NON_Q_VECTORS_VF to the same value as NON_Q_VECTORS_PF. This means that the macro NON_Q_VECTORS(hw) will always return the same value.

Let's just remove this macro, and replace it directly with an enum value on the enum non_q_vectors.

This was detected by cppcheck and fixes the following warnings when building with BUILD=KERNEL

[fm10k_ethtool.c:1123]: (style) Same value in both branches of ternary operator.

[fm10k_ethtool.c:1142]: (style) Same value in both branches of ternary operator.

[fm10k_main.c:1826]: (style) Same value in both branches of ternary operator.

[fm10k_main.c:1849]: (style) Same value in both branches of ternary operator.

[fm10k_main.c:1858]: (style) Same value in both branches of ternary operator.

[fm10k_pci.c:901]: (style) Same value in both branches of ternary operator.

[fm10k_pci.c:1040]: (style) Same value in both branches of ternary operator.

[fm10k_pci.c:1726]: (style) Same value in both branches of ternary operator.

[fm10k_pci.c:1763]: (style) Same value in both branches of ternary operator.

Quoted 7 lines
---
 drivers/net/ethernet/intel/fm10k/fm10k.h         | 10 +++-------
 drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c |  6 ++----
 drivers/net/ethernet/intel/fm10k/fm10k_main.c    |  4 ++--
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c     |  9 ++++-----
 4 files changed, 11 insertions(+), 18 deletions(-)
#37 lore raw

PATCH 19/19 fm10k: fix fm10k_get_fault_pf to read correct address

In reply to Jacob Keller

Fix assignment of the FM10K_FAULT_ADDR_LO register into fault->address by using a bit-wise |= operation. Without this, the low address is completely overwriting the high potion of the address. This caused the fault to incorrectly return only the lower 32 bits of the fault address.

This issue was detected by cppcheck and resolves the following warnings produced by that tool:

[fm10k_pf.c:1668] -> [fm10k_pf.c:1670]: (style) Variable 'fault->address' is reassigned a value before the old one has been used.

[fm10k_pf.c:1669] -> [fm10k_pf.c:1670]: (style) Variable 'fault->address' is reassigned a value before the old one has been used.

---
 drivers/net/ethernet/intel/fm10k/fm10k_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/fm10k/fm10k_pf.c +1 -1
index 095c5b0e4096..be07bfdb0bb4 100644
@@ -1565,7 +1565,7 @@ static s32 fm10k_get_fault_pf(struct fm10k_hw *hw, int type,
 	/* read remaining fields */
 	fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_HI);
 	fault->address <<= 32;
-	fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_LO);
+	fault->address |= fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_LO);
 	fault->specinfo = fm10k_read_reg(hw, type + FM10K_FAULT_SPECINFO);
 
 	/* clear valid bit to allow for next error */
Signature · 1 line
2.22.0.214.g8dca754b1e87
#38 lore raw

PATCH 19/19 fm10k: fix fm10k_get_fault_pf to read correct address

Quoted 19 lines

-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Jacob Keller
Sent: Monday, July 8, 2019 4:13 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 19/19] fm10k: fix fm10k_get_fault_pf to read correct address

Fix assignment of the FM10K_FAULT_ADDR_LO register into fault->address by using a bit-wise |= operation. Without this, the low address is completely overwriting the high potion of the address. This caused the fault to incorrectly return only the lower 32 bits of the fault address.

This issue was detected by cppcheck and resolves the following warnings produced by that tool:

[fm10k_pf.c:1668] -> [fm10k_pf.c:1670]: (style) Variable 'fault->address' is reassigned a value before the old one has been used.

Quoted 7 lines

[fm10k_pf.c:1669] -> [fm10k_pf.c:1670]: (style) Variable 'fault->address' is reassigned a value before the old one has been used.

---
 drivers/net/ethernet/intel/fm10k/fm10k_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)