wifi: iwlwifi: tests: allow same config for different MACs
authorJohannes Berg <johannes.berg@intel.com>
Sun, 4 May 2025 10:26:27 +0000 (13:26 +0300)
committerMiri Korenblit <miriam.rachel.korenblit@intel.com>
Wed, 7 May 2025 03:08:01 +0000 (06:08 +0300)
For different MACs we maintain the configs in different
files, and while it's a small waste of space, this is a
worthwhile trade-off for maintenance and simplicity. So
allow different MAC types to have the same config. This
could allow the same config for two MACs in the same MAC
family, but that's not hugely important. Also simplify
the test to not build a config list, there's no good
reason to do that.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20250504132447.27f5d570eb32.I1649309a0e54a1d446a38c5b2124a582de9f6d61@changeid
drivers/net/wireless/intel/iwlwifi/tests/devinfo.c

index 575327cd3c92325ccf30615e6c0f4f974e8b305e..bf15e8bdc4e840b3edcdb53f00b657937e44ce61 100644 (file)
@@ -60,41 +60,27 @@ static void devinfo_names(struct kunit *test)
 
 static void devinfo_no_cfg_dups(struct kunit *test)
 {
-       /* allocate iwl_dev_info_table_size as upper bound */
-       const struct iwl_cfg **cfgs = kunit_kcalloc(test,
-                                                   iwl_dev_info_table_size,
-                                                   sizeof(*cfgs), GFP_KERNEL);
-       int p = 0;
-
-       KUNIT_ASSERT_NOT_NULL(test, cfgs);
-
-       /* build a list of unique (by pointer) configs first */
        for (int i = 0; i < iwl_dev_info_table_size; i++) {
-               bool found = false;
+               const struct iwl_cfg *cfg_i = iwl_dev_info_table[i].cfg;
 
-               for (int j = 0; j < p; j++) {
-                       if (cfgs[j] == iwl_dev_info_table[i].cfg) {
-                               found = true;
-                               break;
-                       }
-               }
-               if (!found) {
-                       cfgs[p] = iwl_dev_info_table[i].cfg;
-                       p++;
-               }
-       }
+               for (int j = 0; j < i; j++) {
+                       const struct iwl_cfg *cfg_j = iwl_dev_info_table[j].cfg;
 
-       /* check that they're really all different */
-       for (int i = 0; i < p; i++) {
-               struct iwl_cfg cfg_i = *cfgs[i];
+                       if (cfg_i == cfg_j)
+                               continue;
 
-               for (int j = 0; j < i; j++) {
-                       struct iwl_cfg cfg_j = *cfgs[j];
+                       /*
+                        * allow different MAC type to have the same config
+                        * for better maintenance / file split
+                        */
+                       if (iwl_dev_info_table[i].mac_type !=
+                           iwl_dev_info_table[j].mac_type)
+                               continue;
 
-                       KUNIT_EXPECT_NE_MSG(test, memcmp(&cfg_i, &cfg_j,
-                                                        sizeof(cfg_i)), 0,
+                       KUNIT_EXPECT_NE_MSG(test, memcmp(cfg_i, cfg_j,
+                                                        sizeof(*cfg_i)), 0,
                                            "identical configs: %ps and %ps\n",
-                                           cfgs[i], cfgs[j]);
+                                           cfg_i, cfg_j);
                }
        }
 }