]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
nbft: avoid duplicate entries in ssns->hfis
authorMartin Wilck <mwilck@suse.com>
Thu, 11 Jan 2024 10:02:11 +0000 (11:02 +0100)
committerDaniel Wagner <wagi@monom.org>
Mon, 5 Feb 2024 09:35:32 +0000 (10:35 +0100)
The NVMe boot specification does not disallow listing the primary
HFI index again in the secondary HFI list, or listing the same
index multiple times in the secondary HFI list. But such duplicate
entries aren't helpful for consumers of this data. In the worst
case, they might lead to confusion and misconfiguration.
Suppress them.

Signed-off-by: Martin Wilck <mwilck@suse.com>
src/nvme/nbft.c

index 06632323c2a9f826dca07ff2079b370811abeae2..f2ffc21e962f87d225efedcb5da10310ed70a619 100644 (file)
@@ -276,6 +276,27 @@ static int read_ssns(struct nbft_info *nbft,
        }
        ssns->num_hfis = 1;
        for (i = 0; i < le16_to_cpu(raw_ssns->secondary_hfi_assoc_obj.length); i++) {
+               bool duplicate = false;
+               int j;
+
+               for (j = 0; j < i; j++) {
+                       if (ss_hfi_indexes[i] == ss_hfi_indexes[j]) {
+                               duplicate = true;
+                               break;
+                       }
+               }
+
+               if (!duplicate &&
+                   ss_hfi_indexes[i] == raw_ssns->primary_hfi_desc_index)
+                       duplicate = true;
+
+               if (duplicate) {
+                       nvme_msg(NULL, LOG_DEBUG,
+                                "file %s: SSNS %d skipping duplicate HFI index %d\n",
+                                nbft->filename, ssns->index, ss_hfi_indexes[i]);
+                       continue;
+               }
+
                ssns->hfis[i + 1] = hfi_from_index(nbft, ss_hfi_indexes[i]);
                if (ss_hfi_indexes[i] && !ssns->hfis[i + 1])
                        nvme_msg(NULL, LOG_DEBUG,