Skip to contentSkip to conversation

initrd: Fix unused variable warning in rd_load_image() on s390

PATCH Superseded Thorsten Blum 2 participants 3 messages Sep 8, 2025 – Sep 10, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 initrd: Fix unused variable warning in rd_load_image() on s390

The local variable 'rotate' is not used on s390, and building the kernel with W=1 generates the following warning:

init/do_mounts_rd.c:192:17: warning: variable 'rotate' set but not used [-Wunused-but-set-variable]
192 | unsigned short rotate = 0;
| ^
1 warning generated.

Fix this by declaring and using 'rotate' only when CONFIG_S390 is not defined.

---
 init/do_mounts_rd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
init/do_mounts_rd.c +3 -1
index ac021ae6e6fa..cbc4c496cb5f 100644
@@ -189,9 +189,9 @@ int __init rd_load_image(char *from)
 	unsigned long rd_blocks, devblocks;
 	int nblocks, i;
 	char *buf = NULL;
-	unsigned short rotate = 0;
 	decompress_fn decompressor = NULL;
 #if !defined(CONFIG_S390)
+	unsigned short rotate = 0;
 	char rotator[4] = { '|' , '/' , '-' , '\\' };
 #endif
 
@@ -249,7 +249,9 @@ int __init rd_load_image(char *from)
 	for (i = 0; i < nblocks; i++) {
 		if (i && (i % devblocks == 0)) {
 			pr_cont("done disk #1.\n");
+#if !defined(CONFIG_S390)
 			rotate = 0;
+#endif
 			fput(in_file);
 			break;
 		}
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 32 lines · Thorsten Blum

The local variable 'rotate' is not used on s390, and building the kernel with W=1 generates the following warning:

init/do_mounts_rd.c:192:17: warning: variable 'rotate' set but not used [-Wunused-but-set-variable]
192 | unsigned short rotate = 0;
| ^
1 warning generated.

Fix this by declaring and using 'rotate' only when CONFIG_S390 is not defined.

---
 init/do_mounts_rd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
init/do_mounts_rd.c +1 -1
index ac021ae6e6fa..cbc4c496cb5f 100644
@@ -189,9 +189,9 @@ int __init rd_load_image(char *from)
 	unsigned long rd_blocks, devblocks;
 	int nblocks, i;
 	char *buf = NULL;
-	unsigned short rotate = 0;
 	decompress_fn decompressor = NULL;
 #if !defined(CONFIG_S390)
+	unsigned short rotate = 0;
 	char rotator[4] = { '|' , '/' , '-' , '\\' };
 #endif
 

init/do_mounts_rd.c int __init rd_load_image(char *from) · line 254

Quoted 6 lines
init/do_mounts_rd.c +2 -0
@@ -249,7 +249,9 @@ int __init rd_load_image(char *from)
 	for (i = 0; i < nblocks; i++) {
 		if (i && (i % devblocks == 0)) {
 			pr_cont("done disk #1.\n");
+#if !defined(CONFIG_S390)
 			rotate = 0;
+#endif

Instead of adding even more ifdefs, wouldn't it make more sense to get rid of them and leave it up to the compiler to optimize unused stuff away? Something like this instead:

init/do_mounts_rd.c +2 -5
index ac021ae6e6fa..0cc9caf2411d 100644
@@ -191,9 +191,7 @@ int __init rd_load_image(char *from)
 	char *buf = NULL;
 	unsigned short rotate = 0;
 	decompress_fn decompressor = NULL;
-#if !defined(CONFIG_S390)
 	char rotator[4] = { '|' , '/' , '-' , '\\' };
-#endif
 
 	out_file = filp_open("/dev/ram", O_RDWR, 0);
 	if (IS_ERR(out_file))
@@ -255,12 +253,11 @@ int __init rd_load_image(char *from)
 		}
 		kernel_read(in_file, buf, BLOCK_SIZE, &in_pos);
 		kernel_write(out_file, buf, BLOCK_SIZE, &out_pos);
-#if !defined(CONFIG_S390)
 		if (!(i % 16)) {
-			pr_cont("%c\b", rotator[rotate & 0x3]);
+			if (!IS_ENABLED(CONFIG_S390))
+				pr_cont("%c\b", rotator[rotate & 0x3]);
 			rotate++;
 		}
-#endif
 	}
 	pr_cont("done.\n");
 
#2 lore raw
Quoted 3 lines · Heiko Carstens

Instead of adding even more ifdefs, wouldn't it make more sense to get rid of them and leave it up to the compiler to optimize unused stuff away?

Yes, I'll submit a v2.

Thanks,
Thorsten