public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: u-boot@lists.denx.de
Subject: [PATCH v1 09/11] IOMUX: Split out for_each_console_dev() helper macro
Date: Thu, 11 Feb 2021 17:09:42 +0200	[thread overview]
Message-ID: <20210211150944.73252-9-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20210211150944.73252-1-andriy.shevchenko@linux.intel.com>

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>
---
 common/console.c | 15 +++++----------
 common/iomux.c   |  4 +---
 include/iomux.h  |  5 +++++
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/common/console.c b/common/console.c
index 27e881a46bda..197b4de23bb4 100644
--- a/common/console.c
+++ b/common/console.c
@@ -292,8 +292,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) {
@@ -313,8 +312,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);
 	}
@@ -333,11 +331,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);
 	}
@@ -353,8 +349,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);
 	}
diff --git a/common/iomux.c b/common/iomux.c
index a8be1ac7d8ab..5290b13b668b 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -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");
 }
 
diff --git a/include/iomux.h b/include/iomux.h
index 9c2d5796066c..bd4a143b1e60 100644
--- a/include/iomux.h
+++ b/include/iomux.h
@@ -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);
-- 
2.30.0

  parent reply	other threads:[~2021-02-11 15:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11 15:09 [PATCH v1 01/11] stdio: Get rid of dead code, i.e. stdio_deregister() Andy Shevchenko
2021-02-11 15:09 ` [PATCH v1 02/11] stdio: Split out nulldev_register() and move it under #if Andy Shevchenko
2021-02-16 21:56   ` Tom Rini
2021-02-11 15:09 ` [PATCH v1 03/11] stdio: Introduce a new helper stdio_file_to_flags() Andy Shevchenko
2021-02-16 21:56   ` Tom Rini
2021-02-11 15:09 ` [PATCH v1 04/11] console: Switch to use stdio_file_to_flags() Andy Shevchenko
2021-02-16 21:56   ` Tom Rini
2021-02-11 15:09 ` [PATCH v1 05/11] console: Set console device counter in console_devices_set() Andy Shevchenko
2021-02-16 21:57   ` Tom Rini
2021-02-11 15:09 ` [PATCH v1 06/11] console: Set file and devices at one go Andy Shevchenko
2021-02-16 21:57   ` Tom Rini
2021-02-11 15:09 ` [PATCH v1 07/11] IOMUX: Switch to use stdio_file_to_flags() Andy Shevchenko
2021-02-16 21:57   ` Tom Rini
2021-02-11 15:09 ` [PATCH v1 08/11] IOMUX: Split out iomux_match_device() helper Andy Shevchenko
2021-02-16 21:57   ` Tom Rini
2021-02-11 15:09 ` Andy Shevchenko [this message]
2021-02-16 21:57   ` [PATCH v1 09/11] IOMUX: Split out for_each_console_dev() helper macro Tom Rini
2021-02-11 15:09 ` [PATCH v1 10/11] IOMUX: Introduce iomux_replace_device() Andy Shevchenko
2021-02-16 21:57   ` Tom Rini
2021-02-11 15:09 ` [PATCH v1 11/11] usb: kbd: destroy device after console is stopped Andy Shevchenko
2021-02-16 21:57   ` Tom Rini
2021-02-16 21:56 ` [PATCH v1 01/11] stdio: Get rid of dead code, i.e. stdio_deregister() Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210211150944.73252-9-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox