Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8818970d authored by Jacob Keller's avatar Jacob Keller Committed by Jeff Kirsher
Browse files

ixgbe: fix use of list_for_each in ixgbe_enumerate_functions



Fix a bug in the misuse of the list_for_each macro to loop over every
entry in the bus_list. Instead of attempting to loop over the list from
a random entry point, go up to the bus and use the real list_head entry
point. This prevents the possible read or write of unallocated or
incorrectly addressed memory.

Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Tested-by: default avatarPhil Schmitt <phillip.j.schmitt@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 339de30f
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -7973,24 +7973,21 @@ static const struct net_device_ops ixgbe_netdev_ops = {
 **/
static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
{
	struct list_head *entry;
	struct pci_dev *entry;
	int physfns = 0;

	/* Some cards can not use the generic count PCIe functions method,
	 * because they are behind a parent switch, so we hardcode these with
	 * the correct number of functions.
	 */
	if (ixgbe_pcie_from_parent(&adapter->hw)) {
	if (ixgbe_pcie_from_parent(&adapter->hw))
		physfns = 4;
	} else {
		list_for_each(entry, &adapter->pdev->bus_list) {
			struct pci_dev *pdev =
				list_entry(entry, struct pci_dev, bus_list);

	list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
		/* don't count virtual functions */
			if (!pdev->is_virtfn)
		if (!entry->is_virtfn)
			physfns++;
	}
	}

	return physfns;
}