Commit e7f2b70f authored by Hari Prasath Gujulan Elango's avatar Hari Prasath Gujulan Elango Committed by Greg Kroah-Hartman

staging: most: replace multiple if..else with table lookup

Replace multiple if..else if..statements with simple table lookup in two
functions.
Signed-off-by: default avatarHari Prasath Gujulan Elango <hgujulan@visteon.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 17ac98ac
...@@ -79,6 +79,14 @@ struct most_inst_obj { ...@@ -79,6 +79,14 @@ struct most_inst_obj {
struct list_head list; struct list_head list;
}; };
static const struct {
int most_ch_data_type;
char *name;
} ch_data_type[] = { { MOST_CH_CONTROL, "control\n" },
{ MOST_CH_ASYNC, "async\n" },
{ MOST_CH_SYNC, "sync\n" },
{ MOST_CH_ISOC_AVP, "isoc_avp\n"} };
#define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj) #define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj)
/** /**
...@@ -409,14 +417,12 @@ static ssize_t show_set_datatype(struct most_c_obj *c, ...@@ -409,14 +417,12 @@ static ssize_t show_set_datatype(struct most_c_obj *c,
struct most_c_attr *attr, struct most_c_attr *attr,
char *buf) char *buf)
{ {
if (c->cfg.data_type & MOST_CH_CONTROL) int i;
return snprintf(buf, PAGE_SIZE, "control\n");
else if (c->cfg.data_type & MOST_CH_ASYNC) for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
return snprintf(buf, PAGE_SIZE, "async\n"); if (c->cfg.data_type & ch_data_type[i].most_ch_data_type)
else if (c->cfg.data_type & MOST_CH_SYNC) return snprintf(buf, PAGE_SIZE, ch_data_type[i].name);
return snprintf(buf, PAGE_SIZE, "sync\n"); }
else if (c->cfg.data_type & MOST_CH_ISOC_AVP)
return snprintf(buf, PAGE_SIZE, "isoc_avp\n");
return snprintf(buf, PAGE_SIZE, "unconfigured\n"); return snprintf(buf, PAGE_SIZE, "unconfigured\n");
} }
...@@ -425,15 +431,16 @@ static ssize_t store_set_datatype(struct most_c_obj *c, ...@@ -425,15 +431,16 @@ static ssize_t store_set_datatype(struct most_c_obj *c,
const char *buf, const char *buf,
size_t count) size_t count)
{ {
if (!strcmp(buf, "control\n")) { int i;
c->cfg.data_type = MOST_CH_CONTROL;
} else if (!strcmp(buf, "async\n")) { for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
c->cfg.data_type = MOST_CH_ASYNC; if (!strcmp(buf, ch_data_type[i].name)) {
} else if (!strcmp(buf, "sync\n")) { c->cfg.data_type = ch_data_type[i].most_ch_data_type;
c->cfg.data_type = MOST_CH_SYNC; break;
} else if (!strcmp(buf, "isoc_avp\n")) { }
c->cfg.data_type = MOST_CH_ISOC_AVP; }
} else {
if (i == ARRAY_SIZE(ch_data_type)) {
pr_info("WARN: invalid attribute settings\n"); pr_info("WARN: invalid attribute settings\n");
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment