Instead of making the comparison one by one, reuse si_to_str[] array
in ipmi_hardcode_init_one() in conjunction with match_string() API.

Signed-off-by: Andy Shevchenko <andriy.shevche...@linux.intel.com>
---
 drivers/char/ipmi/ipmi_si.h          |  6 +++++-
 drivers/char/ipmi/ipmi_si_hardcode.c | 23 +++++++++--------------
 drivers/char/ipmi/ipmi_si_intf.c     |  3 ++-
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_si.h b/drivers/char/ipmi/ipmi_si.h
index bac0ff86e48e..9492c53eba86 100644
--- a/drivers/char/ipmi/ipmi_si.h
+++ b/drivers/char/ipmi/ipmi_si.h
@@ -18,10 +18,14 @@
 #define DEFAULT_REGSPACING     1
 #define DEFAULT_REGSIZE                1
 
+/* Numbers in this enumerator should be mapped to si_to_str[] */
 enum si_type {
-       SI_TYPE_INVALID, SI_KCS, SI_SMIC, SI_BT
+       SI_TYPE_INVALID, SI_KCS, SI_SMIC, SI_BT, SI_TYPE_MAX
 };
 
+/* Array is defined in the ipmi_si_intf.c */
+extern const char *const si_to_str[];
+
 enum ipmi_addr_space {
        IPMI_IO_ADDR_SPACE, IPMI_MEM_ADDR_SPACE
 };
diff --git a/drivers/char/ipmi/ipmi_si_hardcode.c 
b/drivers/char/ipmi/ipmi_si_hardcode.c
index f6ece7569504..bbcf7483d569 100644
--- a/drivers/char/ipmi/ipmi_si_hardcode.c
+++ b/drivers/char/ipmi/ipmi_si_hardcode.c
@@ -80,26 +80,21 @@ static void __init ipmi_hardcode_init_one(const char 
*si_type_str,
                                          enum ipmi_addr_space addr_space)
 {
        struct ipmi_plat_data p;
+       int t;
 
        memset(&p, 0, sizeof(p));
 
        p.iftype = IPMI_PLAT_IF_SI;
-       if (!si_type_str || !*si_type_str || strcmp(si_type_str, "kcs") == 0) {
+       if (!si_type_str || !*si_type_str) {
                p.type = SI_KCS;
-       } else if (strcmp(si_type_str, "smic") == 0) {
-               p.type = SI_SMIC;
-       } else if (strcmp(si_type_str, "bt") == 0) {
-               p.type = SI_BT;
-       } else if (strcmp(si_type_str, "invalid") == 0) {
-               /*
-                * Allow a firmware-specified interface to be
-                * disabled.
-                */
-               p.type = SI_TYPE_INVALID;
        } else {
-               pr_warn("Interface type specified for interface %d, was 
invalid: %s\n",
-                       i, si_type_str);
-               return;
+               t = match_string(si_to_str, -1, si_type_str);
+               if (t < 0) {
+                       pr_warn("Interface type specified for interface %d, was 
invalid: %s\n",
+                               i, si_type_str);
+                       return;
+               }
+               p.type = t;
        }
 
        p.regsize = regsizes[i];
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index be41a473e3c2..d6ecf88636c4 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -70,7 +70,8 @@ enum si_intf_state {
 #define IPMI_BT_INTMASK_CLEAR_IRQ_BIT  2
 #define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1
 
-static const char * const si_to_str[] = { "invalid", "kcs", "smic", "bt" };
+/* 'invalid' to allow a firmware-specified interface to be disabled */
+const char *const si_to_str[] = { "invalid", "kcs", "smic", "bt", NULL };
 
 static bool initialized;
 
-- 
2.30.2

Reply via email to