Skip to contentSkip to conversation

selftests: cachestat: Fix warning on declaration under label

PATCH In review Sidharth Seela 6 participants 8 messages Sep 29, 2025 – Oct 23, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: cachestat: Fix warning on declaration under label

Fix warning caused from declaration under a case label. The proper way
is to declare variable at the beginning of the function. The warning
came from running clang using LLVM=1; and is as follows:
--
-test_cachestat.c:260:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
260 | char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,

      |

---

tools/testing/selftests/cachestat/test_cachestat.c +2 -2
index c952640f163b..0305e736f2b8 100644
@@ -226,7 +226,7 @@ bool run_cachestat_test(enum file_type type)
 	int syscall_ret;
 	size_t compute_len = PS * 512;
 	struct cachestat_range cs_range = { PS, compute_len };
-	char *filename = "tmpshmcstat";
+	char *filename = "tmpshmcstat", *map;
 	struct cachestat cs;
 	bool ret = true;
 	int fd;
@@ -257,7 +257,7 @@ bool run_cachestat_test(enum file_type type)
 		}
 		break;
 	case FILE_MMAP:
-		char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,
+		map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,
 				 MAP_SHARED, fd, 0);
 
 		if (map == MAP_FAILED) {
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Mon, 29 Sep 2025 17:24:06 +0530 Sidharth Seela <[email protected]>…

Fix warning caused from declaration under a case label. The proper way
is to declare variable at the beginning of the function. The warning
came from running clang using LLVM=1; and is as follows:
--
-test_cachestat.c:260:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
260 | char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,

      |

Thanks,
SJ

[...]

Reviewed-by
#2 lore raw

From: wang lian <[email protected]>

Quoted 9 lines

Fix warning caused from declaration under a case label. The proper way
is to declare variable at the beginning of the function. The warning
came from running clang using LLVM=1; and is as follows:
--
-test_cachestat.c:260:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
260 | char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,

      |

Best regards,
wang lian

maintainer Acked-by
#3 lore raw
In reply to SeongJae Park
Quoted 10 lines · SeongJae Park
Quoted 8 lines · On Mon, 29 Sep 2025 17:24:06 +0530 Sidharth Seela <[email protected]>…

Fix warning caused from declaration under a case label. The proper way
is to declare variable at the beginning of the function. The warning
came from running clang using LLVM=1; and is as follows:
--
-test_cachestat.c:260:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
260 | char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,

       |
Quoted 5 lines
Quoted 1 line

Johannes and Nhat,

Assuming this will go through cachestat tree

Let me know if you would like me to take this through my tree.

thanks,
-- Shuah

maintainer Acked-by
#4 lore raw
Quoted 18 lines · Shuah Khan
Quoted 10 lines · SeongJae Park
Quoted 8 lines · On Mon, 29 Sep 2025 17:24:06 +0530 Sidharth Seela <[email protected]>…

Fix warning caused from declaration under a case label. The proper way
is to declare variable at the beginning of the function. The warning
came from running clang using LLVM=1; and is as follows:
--
-test_cachestat.c:260:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
260 | char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,

       |
Quoted 5 lines
Quoted 1 line
Quoted 6 lines

Johannes and Nhat,

Assuming this will go through cachestat tree

Hi Shuah.

LGTM:

Reviewed-by on v1 1/1
#5 lore raw
In reply to Sidharth Seela
Quoted 11 lines · Sidharth Seela

Fix warning caused from declaration under a case label. The proper way
is to declare variable at the beginning of the function. The warning
came from running clang using LLVM=1; and is as follows:
--
-test_cachestat.c:260:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
260 | char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,

       |

---

maintainer
#6 lore raw
Quoted 6 lines · Dev Jain
Quoted 4 lines · Sidharth Seela

Fix warning caused from declaration under a case label. The proper way is to declare variable at the beginning of the function. The warning came from running clang using LLVM=1; and is as follows:

Sidharth,

Make sure to not use "---" in your commit logs. Everything after this line gets thrown away. I had to go fix it manually.

Quoted 10 lines
Quoted 7 lines

-test_cachestat.c:260:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions] 260 |                 char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE,
       |

---

Applied to linux-kselftest fixes branch for next rc.

thanks,
-- Shuah

#7 lore raw
Quoted 2 lines

Make sure to not use "---" in your commit logs. Everything after this line gets thrown away. I had to go fix it manually.

Sorry, I will make sure that doesn't happen again.

Signature · 2 lines
Thanks,
Sidharth Seela