bnx2x: Search VPD with pci_vpd_find_ro_info_keyword()
authorHeiner Kallweit <hkallweit1@gmail.com>
Sun, 22 Aug 2021 13:54:23 +0000 (15:54 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 24 Aug 2021 18:40:12 +0000 (13:40 -0500)
Use pci_vpd_find_ro_info_keyword() to search for keywords in VPD to
simplify the code.

Use strncasecmp() to match Vendor ID instead of comparing with lower- and
upper-case hex string.

[bhelgaas: convert to strncasecmp()]
Link: https://lore.kernel.org/r/a9f730cf-e31e-902b-7b39-0ff2e99636e0@gmail.com
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c

index 9167196..b6d9089 100644 (file)
@@ -12189,11 +12189,10 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp)
 
 static void bnx2x_read_fwinfo(struct bnx2x *bp)
 {
-       int i, block_end, rodi;
-       char str_id_reg[VENDOR_ID_LEN+1];
-       char str_id_cap[VENDOR_ID_LEN+1];
-       unsigned int vpd_len;
-       u8 *vpd_data, len;
+       char str_id[VENDOR_ID_LEN + 1];
+       unsigned int vpd_len, kw_len;
+       u8 *vpd_data;
+       int rodi;
 
        memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
 
@@ -12201,46 +12200,20 @@ static void bnx2x_read_fwinfo(struct bnx2x *bp)
        if (IS_ERR(vpd_data))
                return;
 
-       /* VPD RO tag should be first tag after identifier string, hence
-        * we should be able to find it in first BNX2X_VPD_LEN chars
-        */
-       i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA);
-       if (i < 0)
-               goto out_not_found;
-
-       block_end = i + PCI_VPD_LRDT_TAG_SIZE +
-                   pci_vpd_lrdt_size(&vpd_data[i]);
-       i += PCI_VPD_LRDT_TAG_SIZE;
-
-       rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
-                                  PCI_VPD_RO_KEYWORD_MFR_ID);
-       if (rodi < 0)
-               goto out_not_found;
-
-       len = pci_vpd_info_field_size(&vpd_data[rodi]);
-
-       if (len != VENDOR_ID_LEN)
+       rodi = pci_vpd_find_ro_info_keyword(vpd_data, vpd_len,
+                                           PCI_VPD_RO_KEYWORD_MFR_ID, &kw_len);
+       if (rodi < 0 || kw_len != VENDOR_ID_LEN)
                goto out_not_found;
 
-       rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
-
        /* vendor specific info */
-       snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
-       snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
-       if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
-           !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
-
-               rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
-                                               PCI_VPD_RO_KEYWORD_VENDOR0);
-               if (rodi >= 0) {
-                       len = pci_vpd_info_field_size(&vpd_data[rodi]);
-
-                       rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
-
-                       if (len < 32 && (len + rodi) <= vpd_len) {
-                               memcpy(bp->fw_ver, &vpd_data[rodi], len);
-                               bp->fw_ver[len] = ' ';
-                       }
+       snprintf(str_id, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
+       if (!strncasecmp(str_id, &vpd_data[rodi], VENDOR_ID_LEN)) {
+               rodi = pci_vpd_find_ro_info_keyword(vpd_data, vpd_len,
+                                                   PCI_VPD_RO_KEYWORD_VENDOR0,
+                                                   &kw_len);
+               if (rodi >= 0 && kw_len < sizeof(bp->fw_ver)) {
+                       memcpy(bp->fw_ver, &vpd_data[rodi], kw_len);
+                       bp->fw_ver[kw_len] = ' ';
                }
        }
 out_not_found: