wifi: iwlwifi: add a kunit test for PCI table duplicates
authorJohannes Berg <johannes.berg@intel.com>
Tue, 19 Mar 2024 08:10:16 +0000 (10:10 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 25 Mar 2024 14:39:10 +0000 (15:39 +0100)
We shouldn't have entries in the table that match the same
device; it's possible to have a specific entry followed by
a less specific entry (i.e. NNNN followed by ANY), but not
entries that are dead, where an earlier entry matches the
same as a later one.

Add a test similar to the existing devinfo test to catch
this situation.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://msgid.link/20240319100755.826b859abd62.I8140d7e9ae52ac50c6830818f8f95ccd0d94b3d3@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/intel/iwlwifi/iwl-config.h
drivers/net/wireless/intel/iwlwifi/pcie/drv.c
drivers/net/wireless/intel/iwlwifi/tests/devinfo.c

index 6aa4f7f9c7082e8f227643c8e4d28c7c9a2ce906..f1e7b15458c1b2bfb205cf1f6766613a023e46d0 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/netdevice.h>
 #include <linux/ieee80211.h>
 #include <linux/nl80211.h>
+#include <linux/mod_devicetable.h>
 #include "iwl-csr.h"
 #include "iwl-drv.h"
 
@@ -484,6 +485,7 @@ const struct iwl_dev_info *
 iwl_pci_find_dev_info(u16 device, u16 subsystem_device,
                      u16 mac_type, u8 mac_step, u16 rf_type, u8 cdb,
                      u8 jacket, u8 rf_id, u8 no_160, u8 cores, u8 rf_step);
+extern const struct pci_device_id iwl_hw_card_ids[];
 #endif
 
 /*
index 916d417886e8feaeb5d474678d3189bc533fac7c..4cf811afdfa52a82c3679b357cc47132c5850f46 100644 (file)
@@ -33,7 +33,7 @@ extern int _invalid_type;
        .driver_data = _ASSIGN_CFG(cfg)
 
 /* Hardware specific file defines the PCI IDs table for that hardware module */
-static const struct pci_device_id iwl_hw_card_ids[] = {
+VISIBLE_IF_IWLWIFI_KUNIT const struct pci_device_id iwl_hw_card_ids[] = {
 #if IS_ENABLED(CONFIG_IWLDVM)
        {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
        {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
@@ -516,6 +516,7 @@ static const struct pci_device_id iwl_hw_card_ids[] = {
        {0}
 };
 MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
+EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_hw_card_ids);
 
 #define _IWL_DEV_INFO(_device, _subdevice, _mac_type, _mac_step, _rf_type, \
                      _rf_id, _rf_step, _no_160, _cores, _cdb, _cfg, _name) \
index 7aa47fce6e2d08a4ce5290e67b91a0b1c5439821..7361b6d0cdb8e5541a6f055a485a4026dfd79c12 100644 (file)
@@ -2,9 +2,10 @@
 /*
  * KUnit tests for the iwlwifi device info table
  *
- * Copyright (C) 2023 Intel Corporation
+ * Copyright (C) 2023-2024 Intel Corporation
  */
 #include <kunit/test.h>
+#include <linux/pci.h>
 #include "iwl-drv.h"
 #include "iwl-config.h"
 
@@ -41,8 +42,31 @@ static void devinfo_table_order(struct kunit *test)
        }
 }
 
+static void devinfo_pci_ids(struct kunit *test)
+{
+       struct pci_dev *dev;
+
+       dev = kunit_kmalloc(test, sizeof(*dev), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, dev);
+
+       for (int i = 0; iwl_hw_card_ids[i].vendor; i++) {
+               const struct pci_device_id *s, *t;
+
+               s = &iwl_hw_card_ids[i];
+               dev->vendor = s->vendor;
+               dev->device = s->device;
+               dev->subsystem_vendor = s->subvendor;
+               dev->subsystem_device = s->subdevice;
+               dev->class = s->class;
+
+               t = pci_match_id(iwl_hw_card_ids, dev);
+               KUNIT_EXPECT_PTR_EQ(test, t, s);
+       }
+}
+
 static struct kunit_case devinfo_test_cases[] = {
        KUNIT_CASE(devinfo_table_order),
+       KUNIT_CASE(devinfo_pci_ids),
        {}
 };