]> git.baikalelectronics.ru Git - kernel.git/commitdiff
PCI/AER: Iterate over error counters instead of error strings
authorMohamed Khalfella <mkhalfella@purestorage.com>
Mon, 9 May 2022 18:14:41 +0000 (18:14 +0000)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 13 Jul 2022 19:45:20 +0000 (14:45 -0500)
Previously we iterated over AER stat *names*, e.g.,
aer_correctable_error_string[32], but the actual stat *counters* may not be
that large, e.g., pdev->aer_stats->dev_cor_errs[16], which means that we
printed junk in the sysfs stats files.

Iterate over the stat counter arrays instead of the names to avoid this
junk.

Also, added a build time check to make sure all
counters have entries in strings array.

Fixes: b38add518b5b ("PCI/AER: Simplify __aer_print_error()")
Link: https://lore.kernel.org/r/20220509181441.31884-1-mkhalfella@purestorage.com
Reported-by: Meeta Saggi <msaggi@purestorage.com>
Signed-off-by: Mohamed Khalfella <mkhalfella@purestorage.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Meeta Saggi <msaggi@purestorage.com>
Reviewed-by: Eric Badger <ebadger@purestorage.com>
Cc: stable@vger.kernel.org
drivers/pci/pcie/aer.c

index 8cfdd46b774ed72ed8003b08f527b2d549eec5f8..e2d8a74f83c341def915af240c45b50f161621d1 100644 (file)
@@ -543,7 +543,7 @@ static const char *aer_agent_string[] = {
        u64 *stats = pdev->aer_stats->stats_array;                      \
        size_t len = 0;                                                 \
                                                                        \
-       for (i = 0; i < ARRAY_SIZE(strings_array); i++) {               \
+       for (i = 0; i < ARRAY_SIZE(pdev->aer_stats->stats_array); i++) {\
                if (strings_array[i])                                   \
                        len += sysfs_emit_at(buf, len, "%s %llu\n",     \
                                             strings_array[i],          \
@@ -1349,6 +1349,11 @@ static int aer_probe(struct pcie_device *dev)
        struct device *device = &dev->device;
        struct pci_dev *port = dev->port;
 
+       BUILD_BUG_ON(ARRAY_SIZE(aer_correctable_error_string) <
+                    AER_MAX_TYPEOF_COR_ERRS);
+       BUILD_BUG_ON(ARRAY_SIZE(aer_uncorrectable_error_string) <
+                    AER_MAX_TYPEOF_UNCOR_ERRS);
+
        /* Limit to Root Ports or Root Complex Event Collectors */
        if ((pci_pcie_type(port) != PCI_EXP_TYPE_RC_EC) &&
            (pci_pcie_type(port) != PCI_EXP_TYPE_ROOT_PORT))