patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Sidharth Seela <sidharthseela@gmail.com>,
	SeongJae Park <sj@kernel.org>, wang lian <lianux.mm@gmail.com>,
	Dev Jain <dev.jain@arm.com>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Nhat Pham <nphamcs@gmail.com>, Sasha Levin <sashal@kernel.org>,
	hannes@cmpxchg.org, nathan@kernel.org, linux-mm@kvack.org,
	llvm@lists.linux.dev
Subject: [PATCH AUTOSEL 6.17] selftests: cachestat: Fix warning on declaration under label
Date: Mon,  3 Nov 2025 13:02:33 -0500	[thread overview]
Message-ID: <20251103180246.4097432-20-sashal@kernel.org> (raw)
In-Reply-To: <20251103180246.4097432-1-sashal@kernel.org>

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


      parent reply	other threads:[~2025-11-03 18:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03 18:02 [PATCH AUTOSEL 6.17-5.10] net: tls: Cancel RX async resync request on rcd_delta overflow Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] sched_ext: Allocate scx_kick_cpus_pnt_seqs lazily using kvzalloc() Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] perf/x86/intel/uncore: Add uncore PMU support for Wildcat Lake Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-6.12] net: tls: Change async resync helpers argument Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-6.1] bcma: don't register devices disabled in OF Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-6.12] blk-crypto: use BLK_STS_INVAL for alignment errors Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] drm/msm: Fix pgtable prealloc error path Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] ALSA: hda/realtek: Add quirk for Lenovo Yoga 7 2-in-1 14AKP10 Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-6.1] cifs: fix typo in enable_gcm_256 module parameter Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] smb: client: handle lack of IPC in dfs_cache_refresh() Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] ASoC: rt721: fix prepare clock stop failed Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] sched_ext: defer queue_balance_callback() until after ops.dispatch Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-5.4] kconfig/nconf: Initialize the default locale at startup Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-5.10] scsi: core: Fix a regression triggered by scsi_host_busy() Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-5.15] selftests: net: use BASH for bareudp testing Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] ALSA: hda/realtek: Fix mute led for HP Victus 15-fa1xxx (MB 8C2D) Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-6.6] x86/microcode/AMD: Limit Entrysign signature checking to known generations Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17] x86/CPU/AMD: Extend Zen6 model range Sasha Levin
2025-11-03 18:02 ` [PATCH AUTOSEL 6.17-5.4] kconfig/mconf: Initialize the default locale at startup Sasha Levin
2025-11-03 18:02 ` Sasha Levin [this message]

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=20251103180246.4097432-20-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=lianux.mm@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=patches@lists.linux.dev \
    --cc=sidharthseela@gmail.com \
    --cc=sj@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=stable@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).