]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
wifi: iwlwifi: tests: check transport configs are not duplicated
authorJohannes Berg <johannes.berg@intel.com>
Fri, 2 May 2025 12:56:19 +0000 (15:56 +0300)
committerMiri Korenblit <miriam.rachel.korenblit@intel.com>
Tue, 6 May 2025 19:22:12 +0000 (22:22 +0300)
Add a kunit test to check that all (used) transport config structs
are not duplicated, since there's no value in having the same info
in two places in memory.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20250502155404.a151af19aaba.Id57f099a899e09318c6218ed1859151f00232b41@changeid
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 1ecd873911bc563d829eebb0242cc024edc01d5d..a9d70b58e134253a302c3823405d28701d99641a 100644 (file)
@@ -305,6 +305,8 @@ struct iwl_fw_mon_regs {
        struct iwl_fw_mon_reg cur_frag;
 };
 
+#define TRANS_CFG_MARKER BIT(0)
+
 /**
  * struct iwl_cfg
  * @trans: the trans-specific configuration part
index b96b85e7d5d8612eb0d46b26afe737299391c68a..83d368ef623a28866db3f9ec81c1cdf468b8783f 100644 (file)
@@ -17,7 +17,6 @@
 #include "iwl-prph.h"
 #include "internal.h"
 
-#define TRANS_CFG_MARKER BIT(0)
 #define _IS_A(cfg, _struct) __builtin_types_compatible_p(typeof(cfg),  \
                                                         struct _struct)
 extern int _invalid_type;
index 0de3a01001d705c949b583ebe69725c2e285fb53..de6e3eaca8cd72703877cbd5f1f2be2a02fd705d 100644 (file)
@@ -126,11 +126,59 @@ static void devinfo_pci_ids(struct kunit *test)
        }
 }
 
+static void devinfo_no_trans_cfg_dups(struct kunit *test)
+{
+       /* allocate iwl_dev_info_table_size as upper bound */
+       const struct iwl_cfg_trans_params **cfgs;
+       int count = 0;
+       int p = 0;
+
+       for (int i = 0; iwl_hw_card_ids[i].vendor; i++)
+               count++;
+
+       cfgs = kunit_kcalloc(test, count, sizeof(*cfgs), GFP_KERNEL);
+       KUNIT_ASSERT_NOT_NULL(test, cfgs);
+
+       /* build a list of unique (by pointer) configs first */
+       for (int i = 0; iwl_hw_card_ids[i].vendor; i++) {
+               struct iwl_cfg_trans_params *cfg;
+               bool found = false;
+
+               if (!(iwl_hw_card_ids[i].driver_data & TRANS_CFG_MARKER))
+                       continue;
+
+               cfg = (void *)(iwl_hw_card_ids[i].driver_data &
+                              ~TRANS_CFG_MARKER);
+
+               for (int j = 0; j < p; j++) {
+                       if (cfgs[j] == cfg) {
+                               found = true;
+                               break;
+                       }
+               }
+               if (!found) {
+                       cfgs[p] = cfg;
+                       p++;
+               }
+       }
+
+       /* check that they're really all different */
+       for (int i = 0; i < p; i++) {
+               for (int j = 0; j < i; j++) {
+                       KUNIT_EXPECT_NE_MSG(test, memcmp(cfgs[i], cfgs[j],
+                                                        sizeof(*cfgs[i])), 0,
+                                           "identical configs: %ps and %ps\n",
+                                           cfgs[i], cfgs[j]);
+               }
+       }
+}
+
 static struct kunit_case devinfo_test_cases[] = {
        KUNIT_CASE(devinfo_table_order),
        KUNIT_CASE(devinfo_names),
        KUNIT_CASE(devinfo_no_cfg_dups),
        KUNIT_CASE(devinfo_pci_ids),
+       KUNIT_CASE(devinfo_no_trans_cfg_dups),
        {}
 };