From: Martin Wilck Date: Thu, 11 Jan 2024 10:02:11 +0000 (+0100) Subject: nbft: avoid duplicate entries in ssns->hfis X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=09f457737a4289f074c142b6d40788600572927f;p=users%2Fsagi%2Flibnvme.git nbft: avoid duplicate entries in ssns->hfis 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 --- diff --git a/src/nvme/nbft.c b/src/nvme/nbft.c index 06632323..f2ffc21e 100644 --- a/src/nvme/nbft.c +++ b/src/nvme/nbft.c @@ -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,