OSDN Git Service

PCI/AER: Use match_string() helper to simplify the code
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 28 Jan 2019 11:57:28 +0000 (13:57 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 29 Jan 2019 22:32:17 +0000 (16:32 -0600)
match_string() returns the array index of a matching string.  Use it
instead of the open-coded implementation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pcie/aer.c

index fed29de..f8fc211 100644 (file)
@@ -117,7 +117,7 @@ bool pci_aer_available(void)
 
 static int ecrc_policy = ECRC_POLICY_DEFAULT;
 
-static const char *ecrc_policy_str[] = {
+static const char * const ecrc_policy_str[] = {
        [ECRC_POLICY_DEFAULT] = "bios",
        [ECRC_POLICY_OFF] = "off",
        [ECRC_POLICY_ON] = "on"
@@ -203,11 +203,8 @@ void pcie_ecrc_get_policy(char *str)
 {
        int i;
 
-       for (i = 0; i < ARRAY_SIZE(ecrc_policy_str); i++)
-               if (!strncmp(str, ecrc_policy_str[i],
-                            strlen(ecrc_policy_str[i])))
-                       break;
-       if (i >= ARRAY_SIZE(ecrc_policy_str))
+       i = match_string(ecrc_policy_str, ARRAY_SIZE(ecrc_policy_str), str);
+       if (i < 0)
                return;
 
        ecrc_policy = i;