Skip to contentSkip to conversation

common: console: move break; statement

PATCH In review Andre Przywara 2 participants 3 messages Mar 25, 2025 – Apr 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: console: move break; statement

In console_setfile(), there is some #ifdef'ed code, updating monitor functions for a U-Boot proper build. This is called inside a switch/case statement, but the closing "break;" is inside the #ifdef section. This doesn't look right: we should not fall through to the error case for an SPL/TPL build.

Move the "break" to be always effective, solving a compiler warning about an untagged implicit fallthrough.

---
Hi,

this seems to be the only real bug I found after enabling -Wimplicit-fallthrough in the first phase of the CI. Please have a look to check whether I am right with this one.

I have about 20 patches that add fallthrough annotations, to fix the other warnings, and will send them out once I polished them up - and after I have figured out what to do with libbzip2.

Cheers,
Andre

 common/console.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/console.c +1 -1
index 863ac6aa9dc..618dbb0255f 100644
@@ -208,8 +208,8 @@ static int console_setfile(int file, struct stdio_dev * dev)
 			gd->jt->printf = printf;
 			break;
 		}
-		break;
 #endif
+		break;
 	default:		/* Invalid file ID */
 		error = -1;
 	}
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Andre Przywara

In console_setfile(), there is some #ifdef'ed code, updating monitor functions for a U-Boot proper build. This is called inside a switch/case statement, but the closing "break;" is inside the #ifdef section. This doesn't look right: we should not fall through to the error case for an SPL/TPL build.

Move the "break" to be always effective, solving a compiler warning about an untagged implicit fallthrough.

Looking at the whole function in context yes, I agree this is right. It probably wasn't a problem in practice because of where / when we don't error check or even call this function in the end.

Signature · 1 line
Tom
#2 lore raw
In reply to Andre Przywara
Quoted 10 lines · Andre Przywara

In console_setfile(), there is some #ifdef'ed code, updating monitor functions for a U-Boot proper build. This is called inside a switch/case statement, but the closing "break;" is inside the #ifdef section. This doesn't look right: we should not fall through to the error case for an SPL/TPL build.

Move the "break" to be always effective, solving a compiler warning about an untagged implicit fallthrough.

[...]

Applied to u-boot/master, thanks!

[1/1] common: console: move break; statement

      commit: 82f5ce11e669d86ac08e6ba800d4a97ad734665b
Signature · 1 line
Tom