ipmi_si: Reuse si_to_str[] array in ipmi_hardcode_init_one()

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.shevchenko@linux.intel.com>
Message-Id: <20210402174334.13466-7-andriy.shevchenko@linux.intel.com>
Signed-off-by: Corey Minyard <cminyard@mvista.com>
This commit is contained in:
Andy Shevchenko 2021-04-02 20:43:30 +03:00 committed by Corey Minyard
parent 649a7d46d0
commit 59cdb2e7c8
3 changed files with 16 additions and 16 deletions

View File

@ -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
};

View File

@ -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];

View File

@ -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;