From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 3/7] console: have for_each_console declare the iterator internally
Date: Mon, 13 Apr 2026 12:09:38 +0200 [thread overview]
Message-ID: <20260413101118.1462119-3-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260413101118.1462119-1-a.fatoum@barebox.org>
Simplify users of the for_each_console macro, by declaring the iterator
variable inside.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/bfetch.c | 1 -
commands/edit.c | 2 --
common/bootm.c | 1 -
common/console.c | 11 -----------
common/console_common.c | 5 -----
include/console.h | 7 +++++--
lib/term.c | 1 -
7 files changed, 5 insertions(+), 23 deletions(-)
diff --git a/commands/bfetch.c b/commands/bfetch.c
index d9c615f65aca..705edb08461a 100644
--- a/commands/bfetch.c
+++ b/commands/bfetch.c
@@ -290,7 +290,6 @@ static void print_shell_console(unsigned *line)
const char *shell;
struct command *cmd;
struct string_list sl;
- struct console_device *console;
if (IS_ENABLED(CONFIG_SHELL_HUSH))
shell = "Hush";
diff --git a/commands/edit.c b/commands/edit.c
index c7262711d01f..4442543b9acb 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -464,8 +464,6 @@ static int read_modal_key(bool is_modal)
static bool is_efi_console_active(void)
{
- struct console_device *cdev;
-
if (!IS_ENABLED(CONFIG_DRIVER_SERIAL_EFI_STDIO))
return false;
diff --git a/common/bootm.c b/common/bootm.c
index d4a3a232743f..d84e7647b389 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -653,7 +653,6 @@ struct image_data *bootm_boot_prep(const struct bootm_data *bootm_data)
}
if (bootm_earlycon) {
- struct console_device *console;
const char *earlycon = NULL;
for_each_console(console) {
diff --git a/common/console.c b/common/console.c
index 30a72b2bb6d2..d7013e72e358 100644
--- a/common/console.c
+++ b/common/console.c
@@ -257,7 +257,6 @@ void console_set_stdoutpath(struct console_device *cdev, unsigned baudrate)
struct console_device *of_console_by_stdout_path(void)
{
- struct console_device *console;
struct device_node *stdout_np;
stdout_np = of_get_stdoutpath(NULL);
@@ -459,7 +458,6 @@ EXPORT_SYMBOL(console_unregister);
static __maybe_unused int console_activate_all_fallback(void)
{
int activate = CONSOLE_STDIOE;
- struct console_device *cdev;
for_each_console(cdev) {
if (cdev->f_active & (CONSOLE_STDOUT | CONSOLE_STDERR))
@@ -487,7 +485,6 @@ postenvironment_initcall(console_activate_all_fallback);
static int getc_raw(void)
{
- struct console_device *cdev;
int active = 0;
while (1) {
@@ -515,8 +512,6 @@ static int getc_raw(void)
static int tstc_raw(void)
{
- struct console_device *cdev;
-
if (!IS_ALLOWED(SCONFIG_CONSOLE_INPUT))
return 0;
@@ -578,7 +573,6 @@ EXPORT_SYMBOL(tstc);
int console_putc(unsigned int ch, char c)
{
- struct console_device *cdev;
int init = initialized;
bool crlf = c == '\n';
@@ -613,7 +607,6 @@ EXPORT_SYMBOL(console_putc);
int console_puts(unsigned int ch, const char *str)
{
- struct console_device *cdev;
const char *s = str;
int n = 0;
@@ -636,8 +629,6 @@ EXPORT_SYMBOL(console_puts);
void console_putbin(unsigned int ch, const u8 *str, size_t len)
{
- struct console_device *cdev;
-
switch (initialized) {
case CONSOLE_UNINITIALIZED:
console_init_early();
@@ -667,8 +658,6 @@ EXPORT_SYMBOL(console_putbin);
void console_flush(void)
{
- struct console_device *cdev;
-
for_each_console(cdev) {
if (cdev->flush)
cdev->flush(cdev);
diff --git a/common/console_common.c b/common/console_common.c
index e3b49200c538..1d98e4ec1bcc 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -308,8 +308,6 @@ EXPORT_SYMBOL(vprintf);
struct console_device *console_get_by_dev(struct device *dev)
{
- struct console_device *cdev;
-
for_each_console(cdev) {
if (cdev->dev == dev)
return cdev;
@@ -321,8 +319,6 @@ EXPORT_SYMBOL(console_get_by_dev);
struct console_device *console_get_by_name(const char *name)
{
- struct console_device *cdev;
-
for_each_console(cdev) {
if (cdev->devname && !strcmp(cdev->devname, name))
return cdev;
@@ -340,7 +336,6 @@ EXPORT_SYMBOL(console_get_by_name);
*/
struct console_device *console_get_first_interactive(void)
{
- struct console_device *cdev;
const unsigned char active = CONSOLE_STDIN | CONSOLE_STDOUT;
/* if no console input is allows, then we can't have STDIN on any. */
diff --git a/include/console.h b/include/console.h
index 353a5088a547..082d1ac8a924 100644
--- a/include/console.h
+++ b/include/console.h
@@ -198,7 +198,9 @@ bool console_allow_color(void);
#ifndef CONFIG_CONSOLE_NONE
extern struct list_head console_list;
-#define for_each_console(console) list_for_each_entry(console, &console_list, list)
+#define for_each_console(console) \
+ scoped_var(struct console_device *console) \
+ list_for_each_entry(console, &console_list, list)
struct console_device *console_get_first_interactive(void);
@@ -210,7 +212,8 @@ static inline int barebox_set_loglevel(int loglevel)
return old_loglevel;
}
#else
-#define for_each_console(console) while (((void)console, 0))
+#define for_each_console(console) \
+ scoped_var(struct console_device *console) while (((void)console, 0))
static inline struct console_device *console_get_first_interactive(void)
{
diff --git a/lib/term.c b/lib/term.c
index 8b4de96c63a4..669d48fd4d8c 100644
--- a/lib/term.c
+++ b/lib/term.c
@@ -109,7 +109,6 @@ int term_getsize(int *screenwidth, int *screenheight)
{
int width = INT_MAX, height = INT_MAX;
bool found = false;
- struct console_device *cdev;
for_each_console(cdev) {
int w, h;
--
2.47.3
next prev parent reply other threads:[~2026-04-13 10:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 10:09 [PATCH 1/7] console: return characters written from console_putc Ahmad Fatoum
2026-04-13 10:09 ` [PATCH 2/7] stddef: implement scoped_var for use in iterators Ahmad Fatoum
2026-04-13 10:09 ` Ahmad Fatoum [this message]
2026-04-13 10:09 ` [PATCH 4/7] console: make console_puts and friends accept a console_device Ahmad Fatoum
2026-04-13 10:09 ` [PATCH 5/7] console: implement console_putc in terms of console_putbin Ahmad Fatoum
2026-04-13 10:09 ` [PATCH 6/7] console: implement console_printf Ahmad Fatoum
2026-04-13 10:09 ` [PATCH 7/7] commands: dmesg: give log_print a console_device parameter Ahmad Fatoum
2026-04-13 12:28 ` [PATCH 1/7] console: return characters written from console_putc Sascha Hauer
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=20260413101118.1462119-3-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/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