Blob Blame History Raw
From 3f7320428fa41a4c8be9c6f3d0cc06beeb0b3df8 Mon Sep 17 00:00:00 2001
From: Johannes Berg <johannes.berg@intel.com>
Date: Sun, 24 Oct 2021 16:55:05 +0300
Subject: [PATCH] iwlwifi: pcie: simplify iwl_pci_find_dev_info()
Git-commit: 3f7320428fa41a4c8be9c6f3d0cc06beeb0b3df8
Patch-mainline: v5.16-rc1
References: bsc#1202131

We currently match the list of devices from the start to
the end, but then find the *last* match, so we need to
look at each and every entry. We don't want to change the
semantics ("most generic entry must come first"), so just
change the order of matching to be back-to-front, then we
can break out once we find a match.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20211024165252.abd85e1391cb.I7681fe90735044cc1c59f120e8591b7ac125535d@changeid
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 drivers/net/wireless/intel/iwlwifi/pcie/drv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
index 3276f04cfd60..c574f041f096 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
@@ -1339,10 +1339,9 @@ iwl_pci_find_dev_info(u16 device, u16 subsystem_device,
 		      u16 mac_type, u8 mac_step,
 		      u16 rf_type, u8 cdb, u8 rf_id, u8 no_160, u8 cores)
 {
-	const struct iwl_dev_info *ret = NULL;
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(iwl_dev_info_table); i++) {
+	for (i = ARRAY_SIZE(iwl_dev_info_table) - 1; i >= 0; i--) {
 		const struct iwl_dev_info *dev_info = &iwl_dev_info_table[i];
 
 		if (dev_info->device != (u16)IWL_CFG_ANY &&
@@ -1381,10 +1380,10 @@ iwl_pci_find_dev_info(u16 device, u16 subsystem_device,
 		    dev_info->cores != cores)
 			continue;
 
-		ret = dev_info;
+		return dev_info;
 	}
 
-	return ret;
+	return NULL;
 }
 
 static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
-- 
2.35.3