aboutsummaryrefslogtreecommitdiff
path: root/common/iomux.c
diff options
context:
space:
mode:
authorAndy Shevchenko2021-02-11 17:09:41 +0200
committerTom Rini2021-02-16 11:16:08 -0500
commitb672c1619bb9615aff3ebbe15c20083fd0f58f9b (patch)
treef53f556f1aefe4e1bc79d228188ed4a8b06ccef1 /common/iomux.c
parent658d6c583663ae4f37cb6a5e104b2bf864fbc497 (diff)
IOMUX: Split out iomux_match_device() helper
Deduplicate the code used in a few places by splitting out a common helper. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Diffstat (limited to 'common/iomux.c')
-rw-r--r--common/iomux.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/common/iomux.c b/common/iomux.c
index 5d027561bb6..a8be1ac7d8a 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -22,11 +22,21 @@ void iomux_printdevs(const int console)
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. */
int iomux_doenv(const int console, const char *arg)
{
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 *dev;
@@ -96,14 +106,8 @@ int iomux_doenv(const int console, const char *arg)
/*
* Prevent multiple entries for a device.
*/
- repeat = 0;
- for (k = 0; k < cs_idx; k++) {
- if (dev == cons_set[k]) {
- repeat++;
- break;
- }
- }
- if (repeat)
+ repeat = iomux_match_device(cons_set, cs_idx, dev);
+ if (repeat >= 0)
continue;
/*
* Try assigning the specified device.
@@ -129,10 +133,7 @@ int iomux_doenv(const int console, const char *arg)
/* Stop dropped consoles */
for (i = 0; i < repeat; i++) {
- for (j = 0; j < cs_idx; j++) {
- if (old_set[i] == cons_set[j])
- break;
- }
+ j = iomux_match_device(cons_set, cs_idx, old_set[i]);
if (j == cs_idx)
console_stop(console, old_set[i]);
}