tg3: Validate VPD checksum with pci_vpd_check_csum()
authorHeiner Kallweit <hkallweit1@gmail.com>
Wed, 18 Aug 2021 19:05:26 +0000 (21:05 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 20 Aug 2021 20:49:01 +0000 (15:49 -0500)
Validate the VPD checksum with pci_vpd_check_csum() to simplify the code.

Link: https://lore.kernel.org/r/7297fce9-47db-3b86-366e-10b9ef43beaf@gmail.com
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/net/ethernet/broadcom/tg3.c

index 779b1009da1c978b4cad21f684d48c8696da44b1..7bf16c1925cc598d1002658b19f1113ff017d395 100644 (file)
@@ -13010,33 +13010,10 @@ static int tg3_test_nvram(struct tg3 *tp)
        if (!buf)
                return -ENOMEM;
 
-       i = pci_vpd_find_tag((u8 *)buf, len, PCI_VPD_LRDT_RO_DATA);
-       if (i > 0) {
-               j = pci_vpd_lrdt_size(&((u8 *)buf)[i]);
-               if (j < 0)
-                       goto out;
-
-               if (i + PCI_VPD_LRDT_TAG_SIZE + j > len)
-                       goto out;
-
-               i += PCI_VPD_LRDT_TAG_SIZE;
-               j = pci_vpd_find_info_keyword((u8 *)buf, i, j,
-                                             PCI_VPD_RO_KEYWORD_CHKSUM);
-               if (j > 0) {
-                       u8 csum8 = 0;
-
-                       j += PCI_VPD_INFO_FLD_HDR_SIZE;
-
-                       for (i = 0; i <= j; i++)
-                               csum8 += ((u8 *)buf)[i];
-
-                       if (csum8)
-                               goto out;
-               }
-       }
-
-       err = 0;
-
+       err = pci_vpd_check_csum(buf, len);
+       /* go on if no checksum found */
+       if (err == 1)
+               err = 0;
 out:
        kfree(buf);
        return err;