* [PATCH AUTOSEL 6.17] selftests: cachestat: Fix warning on declaration under label
[not found] <20251103180246.4097432-1-sashal@kernel.org>
@ 2025-11-03 18:02 ` Sasha Levin
0 siblings, 0 replies; only message in thread
From: Sasha Levin @ 2025-11-03 18:02 UTC (permalink / raw)
To: patches, stable
Cc: Sidharth Seela, SeongJae Park, wang lian, Dev Jain, Shuah Khan,
Nhat Pham, Sasha Levin, hannes, nathan, linux-mm, llvm
From: Sidharth Seela <sidharthseela@gmail.com>
[ Upstream commit 920aa3a7705a061cb3004572d8b7932b54463dbf ]
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,
|
Link: https://lore.kernel.org/r/20250929115405.25695-2-sidharthseela@gmail.com
Signed-off-by: Sidharth Seela <sidharthseela@gmail.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Reviewed-by: wang lian <lianux.mm@gmail.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Acked-by: Nhat Pham <nphamcs@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
Now let me compile my comprehensive analysis based on all the data
gathered:
## Analysis Summary
**ANSWER: YES**
This commit should be backported to stable kernel trees (specifically
6.17.y and any newer stable branches that contain the buggy code).
### Detailed Analysis
#### 1. **Code Context and Bug Identification**
Using semantic code analysis tools and git history examination, I
identified:
- **Function analyzed**: `run_cachestat_test()` in
tools/testing/selftests/cachestat/test_cachestat.c (lines 222-295)
- **Bug introduced**: Commit d6a511dea45ce (July 2025) - "selftests:
cachestat: add tests for mmap"
- **Affected versions**: v6.17 and later (confirmed via `git tag
--contains d6a511dea45ce`)
- **Bug confirmed in v6.17.7**: Using `git show
v6.17.7:tools/testing/selftests/cachestat/test_cachestat.c`, I
verified the problematic code exists:
```c
case FILE_MMAP:
char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE, //
VIOLATION: declaration after label
```
#### 2. **Semantic Analysis Used**
- **mcp__semcode__find_function**: Located `run_cachestat_test()`
function and confirmed the bug exists at line 260
- **mcp__semcode__find_callers**: Identified that this is a test
function called from main
- **Git history analysis**: Traced bug introduction and verified no
prior fix exists
#### 3. **Nature of the Fix**
The fix is **minimal and safe**:
- **Changed**: Variable `char *map` declaration moved from line 260
(under case label) to line 229 (with other variable declarations)
- **Lines modified**: Only 2 lines changed (declaration location)
- **Risk level**: Zero - pure code style fix with no behavioral changes
- **Compiler warning**: `-Wc23-extensions` when building with clang
LLVM=1
#### 4. **Backporting Precedent**
I found strong precedent for backporting selftest build fixes:
- **Commit 90c1ffd1347f3** (bc4d5f5d2debf upstream): "selftests:
cachestat: Fix build warnings on ppc64"
- Similar warning fix for the same test file
- **WAS backported to stable** (shows "Signed-off-by: Sasha Levin"
indicating automated stable backport)
- Establishes that cachestat selftest build fixes ARE appropriate for
stable trees
#### 5. **Impact Assessment**
- **Scope**: Affects only userspace selftest code, not kernel runtime
- **User Impact**: Developers building selftests with clang will get
warnings without this fix
- **Build Impact**: Does NOT break builds (warning, not error), but
reduces noise and follows best practices
- **Testing Impact**: Enables cleaner CI/CD pipelines that treat
warnings as errors
#### 6. **Stable Tree Compliance**
✅ **Fixes a real issue**: Violates C language standards (pre-C23)
✅ **Small and contained**: 2-line change, single file
✅ **No architectural changes**: Pure variable declaration movement
✅ **No new features**: Maintains existing functionality
✅ **Well-reviewed**: Multiple Reviewed-by, Acked-by tags from
maintainers
✅ **Precedent exists**: Similar fixes were backported before
#### 7. **Commit Quality**
The commit has proper maintainer approval:
- Signed-off-by: Shuah Khan (selftest maintainer)
- Reviewed-by: SeongJae Park
- Reviewed-by: wang lian
- Reviewed-by: Dev Jain
- Acked-by: Shuah Khan
- Acked-by: Nhat Pham
### Conclusion
This is a **low-risk, high-value** backport candidate that:
1. Fixes legitimate C standards compliance issue
2. Improves developer experience when building with clang
3. Has precedent for similar backports in the same file
4. Contains zero functional changes
5. Has strong maintainer approval
The commit follows all stable kernel rules and should be backported to
6.17.y and any other stable trees containing the buggy code introduced
in d6a511dea45ce.
tools/testing/selftests/cachestat/test_cachestat.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/cachestat/test_cachestat.c b/tools/testing/selftests/cachestat/test_cachestat.c
index c952640f163b5..ab838bcb9ec55 100644
--- a/tools/testing/selftests/cachestat/test_cachestat.c
+++ b/tools/testing/selftests/cachestat/test_cachestat.c
@@ -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) {
--
2.51.0
^ permalink raw reply related [flat|nested] only message in thread