IOMUX: Split out for_each_console_dev() helper macro

It is not only less lines of code, but also better readability
when new macro is being in use. Introduce for_each_console_dev()
helper macro and convert current users to it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
This commit is contained in:
Andy Shevchenko 2021-02-11 17:09:42 +02:00 committed by Tom Rini
parent b672c1619b
commit 400797cad3
3 changed files with 11 additions and 13 deletions

View File

@ -293,8 +293,7 @@ static int console_tstc(int file)
int prev;
prev = disable_ctrlc(1);
for (i = 0; i < cd_count[file]; i++) {
dev = console_devices[file][i];
for_each_console_dev(i, file, dev) {
if (dev->tstc != NULL) {
ret = dev->tstc(dev);
if (ret > 0) {
@ -314,8 +313,7 @@ static void console_putc(int file, const char c)
int i;
struct stdio_dev *dev;
for (i = 0; i < cd_count[file]; i++) {
dev = console_devices[file][i];
for_each_console_dev(i, file, dev) {
if (dev->putc != NULL)
dev->putc(dev, c);
}
@ -334,11 +332,9 @@ static void console_puts_select(int file, bool serial_only, const char *s)
int i;
struct stdio_dev *dev;
for (i = 0; i < cd_count[file]; i++) {
bool is_serial;
for_each_console_dev(i, file, dev) {
bool is_serial = console_dev_is_serial(dev);
dev = console_devices[file][i];
is_serial = console_dev_is_serial(dev);
if (dev->puts && serial_only == is_serial)
dev->puts(dev, s);
}
@ -354,8 +350,7 @@ static void console_puts(int file, const char *s)
int i;
struct stdio_dev *dev;
for (i = 0; i < cd_count[file]; i++) {
dev = console_devices[file][i];
for_each_console_dev(i, file, dev) {
if (dev->puts != NULL)
dev->puts(dev, s);
}

View File

@ -15,10 +15,8 @@ void iomux_printdevs(const int console)
int i;
struct stdio_dev *dev;
for (i = 0; i < cd_count[console]; i++) {
dev = console_devices[console][i];
for_each_console_dev(i, console, dev)
printf("%s ", dev->name);
}
printf("\n");
}

View File

@ -24,6 +24,11 @@ extern struct stdio_dev **console_devices[MAX_FILES];
*/
extern int cd_count[MAX_FILES];
#define for_each_console_dev(i, file, dev) \
for (i = 0, dev = console_devices[file][i]; \
i < cd_count[file]; \
i++, dev = console_devices[file][i])
int iomux_match_device(struct stdio_dev **, const int, struct stdio_dev *);
int iomux_doenv(const int, const char *);
void iomux_printdevs(const int);