Skip to content

Commit 8b25125

Browse files
committed
wifi: iwlwifi: add a kunit test for PCI table duplicates
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 <[email protected]> Signed-off-by: Miri Korenblit <[email protected]> Link: https://msgid.link/20240319100755.826b859abd62.I8140d7e9ae52ac50c6830818f8f95ccd0d94b3d3@changeid Signed-off-by: Johannes Berg <[email protected]>
1 parent 1758f97 commit 8b25125

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

drivers/net/wireless/intel/iwlwifi/iwl-config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/netdevice.h>
1212
#include <linux/ieee80211.h>
1313
#include <linux/nl80211.h>
14+
#include <linux/mod_devicetable.h>
1415
#include "iwl-csr.h"
1516
#include "iwl-drv.h"
1617

@@ -484,6 +485,7 @@ const struct iwl_dev_info *
484485
iwl_pci_find_dev_info(u16 device, u16 subsystem_device,
485486
u16 mac_type, u8 mac_step, u16 rf_type, u8 cdb,
486487
u8 jacket, u8 rf_id, u8 no_160, u8 cores, u8 rf_step);
488+
extern const struct pci_device_id iwl_hw_card_ids[];
487489
#endif
488490

489491
/*

drivers/net/wireless/intel/iwlwifi/pcie/drv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern int _invalid_type;
3333
.driver_data = _ASSIGN_CFG(cfg)
3434

3535
/* Hardware specific file defines the PCI IDs table for that hardware module */
36-
static const struct pci_device_id iwl_hw_card_ids[] = {
36+
VISIBLE_IF_IWLWIFI_KUNIT const struct pci_device_id iwl_hw_card_ids[] = {
3737
#if IS_ENABLED(CONFIG_IWLDVM)
3838
{IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
3939
{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[] = {
516516
{0}
517517
};
518518
MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
519+
EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_hw_card_ids);
519520

520521
#define _IWL_DEV_INFO(_device, _subdevice, _mac_type, _mac_step, _rf_type, \
521522
_rf_id, _rf_step, _no_160, _cores, _cdb, _cfg, _name) \

drivers/net/wireless/intel/iwlwifi/tests/devinfo.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
/*
33
* KUnit tests for the iwlwifi device info table
44
*
5-
* Copyright (C) 2023 Intel Corporation
5+
* Copyright (C) 2023-2024 Intel Corporation
66
*/
77
#include <kunit/test.h>
8+
#include <linux/pci.h>
89
#include "iwl-drv.h"
910
#include "iwl-config.h"
1011

@@ -41,8 +42,31 @@ static void devinfo_table_order(struct kunit *test)
4142
}
4243
}
4344

45+
static void devinfo_pci_ids(struct kunit *test)
46+
{
47+
struct pci_dev *dev;
48+
49+
dev = kunit_kmalloc(test, sizeof(*dev), GFP_KERNEL);
50+
KUNIT_ASSERT_NOT_NULL(test, dev);
51+
52+
for (int i = 0; iwl_hw_card_ids[i].vendor; i++) {
53+
const struct pci_device_id *s, *t;
54+
55+
s = &iwl_hw_card_ids[i];
56+
dev->vendor = s->vendor;
57+
dev->device = s->device;
58+
dev->subsystem_vendor = s->subvendor;
59+
dev->subsystem_device = s->subdevice;
60+
dev->class = s->class;
61+
62+
t = pci_match_id(iwl_hw_card_ids, dev);
63+
KUNIT_EXPECT_PTR_EQ(test, t, s);
64+
}
65+
}
66+
4467
static struct kunit_case devinfo_test_cases[] = {
4568
KUNIT_CASE(devinfo_table_order),
69+
KUNIT_CASE(devinfo_pci_ids),
4670
{}
4771
};
4872

0 commit comments

Comments
 (0)