提交 b672c161 编写于 作者: A Andy Shevchenko 提交者: Tom Rini

IOMUX: Split out iomux_match_device() helper

Deduplicate the code used in a few places by splitting out a common helper.
Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
上级 658d6c58
...@@ -252,15 +252,14 @@ static void console_devices_set(int file, struct stdio_dev *dev) ...@@ -252,15 +252,14 @@ static void console_devices_set(int file, struct stdio_dev *dev)
*/ */
static bool console_needs_start_stop(int file, struct stdio_dev *sdev) static bool console_needs_start_stop(int file, struct stdio_dev *sdev)
{ {
int i, j; int i;
for (i = 0; i < ARRAY_SIZE(cd_count); i++) { for (i = 0; i < ARRAY_SIZE(cd_count); i++) {
if (i == file) if (i == file)
continue; continue;
for (j = 0; j < cd_count[i]; j++) if (iomux_match_device(console_devices[i], cd_count[i], sdev) >= 0)
if (console_devices[i][j] == sdev) return false;
return false;
} }
return true; return true;
} }
......
...@@ -22,11 +22,21 @@ void iomux_printdevs(const int console) ...@@ -22,11 +22,21 @@ void iomux_printdevs(const int console)
printf("\n"); printf("\n");
} }
int iomux_match_device(struct stdio_dev **set, const int n, struct stdio_dev *sdev)
{
int i;
for (i = 0; i < n; i++)
if (sdev == set[i])
return i;
return -ENOENT;
}
/* This tries to preserve the old list if an error occurs. */ /* This tries to preserve the old list if an error occurs. */
int iomux_doenv(const int console, const char *arg) int iomux_doenv(const int console, const char *arg)
{ {
char *console_args, *temp, **start; char *console_args, *temp, **start;
int i, j, k, io_flag, cs_idx, repeat; int i, j, io_flag, cs_idx, repeat;
struct stdio_dev **cons_set, **old_set; struct stdio_dev **cons_set, **old_set;
struct stdio_dev *dev; struct stdio_dev *dev;
...@@ -96,14 +106,8 @@ int iomux_doenv(const int console, const char *arg) ...@@ -96,14 +106,8 @@ int iomux_doenv(const int console, const char *arg)
/* /*
* Prevent multiple entries for a device. * Prevent multiple entries for a device.
*/ */
repeat = 0; repeat = iomux_match_device(cons_set, cs_idx, dev);
for (k = 0; k < cs_idx; k++) { if (repeat >= 0)
if (dev == cons_set[k]) {
repeat++;
break;
}
}
if (repeat)
continue; continue;
/* /*
* Try assigning the specified device. * Try assigning the specified device.
...@@ -129,10 +133,7 @@ int iomux_doenv(const int console, const char *arg) ...@@ -129,10 +133,7 @@ int iomux_doenv(const int console, const char *arg)
/* Stop dropped consoles */ /* Stop dropped consoles */
for (i = 0; i < repeat; i++) { for (i = 0; i < repeat; i++) {
for (j = 0; j < cs_idx; j++) { j = iomux_match_device(cons_set, cs_idx, old_set[i]);
if (old_set[i] == cons_set[j])
break;
}
if (j == cs_idx) if (j == cs_idx)
console_stop(console, old_set[i]); console_stop(console, old_set[i]);
} }
......
...@@ -24,6 +24,7 @@ extern struct stdio_dev **console_devices[MAX_FILES]; ...@@ -24,6 +24,7 @@ extern struct stdio_dev **console_devices[MAX_FILES];
*/ */
extern int cd_count[MAX_FILES]; extern int cd_count[MAX_FILES];
int iomux_match_device(struct stdio_dev **, const int, struct stdio_dev *);
int iomux_doenv(const int, const char *); int iomux_doenv(const int, const char *);
void iomux_printdevs(const int); void iomux_printdevs(const int);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册