[PATCH] scripts/checkpatch: Match paths beginning with hw/
TANG Tiancheng <[email protected]> Tue, 04 Aug 2026 22:37:19 +0800
| Newsgroups | gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <20260804-b4-checkpatch-hw-path-v1-1-91b88679f2d9@linux.alibaba.com> |
Patch mode strips the leading a/ and b/ components from file paths,
leaving repository-relative paths such as hw/riscv/foo.c. The checks
for qemu_bh_new() and aio_bh_new() currently require /hw/ in $realfile,
so they miss paths beginning with hw/ in both normal Git patches and
--file mode.
Match either the start of $realfile or a slash before hw/, making
patch and file modes consistent while preserving nested /hw/ matches.
Fixes: ef56ffbdd6b0 ("checkpatch: add qemu_bh_new/aio_bh_new checks")
Signed-off-by: TANG Tiancheng <[email protected]>
---
The checks for qemu_bh_new() and aio_bh_new() introduced by
ef56ffbdd6b0 are intended to cover files under hw/. In patch mode,
checkpatch removes Git's leading a/ and b/ path components before
setting $realfile. A file under the repository's hw/ directory is
therefore represented as hw/foo.c. Since the checks require /hw/,
they do not recognize that path. The same false negative occurs in
--file mode when given a repository-relative path such as
hw/misc/i2c-echo.c.
The problem can be reproduced from an unmodified upstream QEMU checkout
at the series base:
$ git show b14037f37f9 -- hw/misc/i2c-echo.c |
scripts/checkpatch.pl --patch \
--test-only=aio_bh_new_guarded --no-summary -
Your patch has no obvious style problems and is ready for submission.
Commit b14037f37f9 adds a qemu_bh_new() call under hw/, so that result is
a false negative. Repository-relative file mode reproduces the issue:
$ scripts/checkpatch.pl --file hw/misc/i2c-echo.c \
--test-only=aio_bh_new_guarded --no-summary
hw/misc/i2c-echo.c has no obvious style problems and is ready for
submission.
Before this patch, both invocations succeed without reporting the call.
After this patch, both report:
ERROR: use aio_bh_new_guarded() instead of qemu_bh_new*() to avoid
reentrancy problems
and return failure as expected. The analogous aio_bh_new() check was
verified with hw/i386/kvm/xen_evtchn.c.
---
scripts/checkpatch.pl | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 03f35e75012c8c7a00b67f036e4befb2ea162d4a..9ae7693a4f388597dc11a58a85736d511fbcc62c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3223,11 +3223,13 @@ sub process {
ERROR("use sigaction to establish signal handlers; signal is not portable\n" . $herecurr);
}
# recommend aio_bh_new_guarded instead of legacy qemu_bh_new / qemu_bh_new_guarded
- if ($realfile =~ /.*\/hw\/.*/ && $line =~ /\bqemu_bh_new(_guarded)?\s*\(/) {
+ if ($realfile =~ m{(?:^|/)hw/} &&
+ $line =~ /\bqemu_bh_new(_guarded)?\s*\(/) {
ERROR("use aio_bh_new_guarded() instead of qemu_bh_new*() to avoid reentrancy problems\n" . $herecurr);
}
# recommend aio_bh_new_guarded instead of aio_bh_new
- if ($realfile =~ /.*\/hw\/.*/ && $line =~ /\baio_bh_new\s*\(/) {
+ if ($realfile =~ m{(?:^|/)hw/} &&
+ $line =~ /\baio_bh_new\s*\(/) {
ERROR("use aio_bh_new_guarded() instead of aio_bh_new() to avoid reentrancy problems\n" . $herecurr);
}
# check for DEVICE_NATIVE_ENDIAN, use explicit endianness instead
---
base-commit: b428fe036233cbd15d37e3c027ab6ca4d3661a80
change-id: 20260804-b4-checkpatch-hw-path-cd477b5357b8
Best regards,
--
TANG Tiancheng <[email protected]>