hujun260 opened a new pull request, #22038:
URL: https://github.com/apache/nuttx/pull/22038
# arch/arm: unify ARM-M NVIC priority header and fix nxstyle issues in
touched files
## Summary
This PR contains two commits:
1. **`arch/arm: fix nxstyle issues in ARM-M IRQ sources`** — clean up
existing
nxstyle violations in the 15 files that commit 2 touches, plus one real
compile error (`else (cond)`).
2. **`arm_m: merge arm/include/armv6/7/8-m/nvicpri.h into arm_m`** — move the
duplicated NVIC priority definitions used by ARMv6-M, ARMv7-M and ARMv8-M
into the common `arch/arm/include/arm_m/nvicpri.h`.
The order matters. `tools/checkpatch.sh -g <commit>` runs `nxstyle` over the
**entire** file for every file a commit touches, not just the changed hunks.
Commit 2 touches 15 source files that were already carrying nxstyle errors on
`master`, so without commit 1 first, commit 2 fails the Check workflow on its
own. Commit 1 is therefore a prerequisite, not an unrelated drive-by cleanup.
## Commits
```text
be0b6610012fda93843c3c621756d0c3c71c1401 arm_m: merge
arm/include/armv6/7/8-m/nvicpri.h into arm_m
0027bdca41da8d6fa849c19195540c698f701e3f arch/arm: fix nxstyle issues in
ARM-M IRQ sources
9fdcbb56fbb3b00f97cdbea779156168663cdc18 (base) Documentation/sim: describe
the JPEG m2m decoder
```
| Commit | Files | Insertions | Deletions |
| ------ | ----: | ---------: | --------: |
| `0027bdca41d` nxstyle fixes | 15 | 197 | 148 |
| `be0b6610012` nvicpri merge | 57 | 59 | 137 |
| Total range | 57 | 256 | 285 |
## Commit 1: nxstyle fixes
### Why this commit exists
`tools/checkpatch.sh` (line 497 in the current tree) rebuilds `nxstyle`, then
`check_ranges()` resolves each `+++ b/<path>` from `git diff` and calls
`check_file <path>` with **no line range** unless `-r` is passed. The Check
workflow (`.github/workflows/check.yml:52`) runs:
```text
../nuttx/tools/checkpatch.sh -c -u -m -g $breaking_opts $commits
```
There is no `-r`, so every file listed in the diff is linted in full. The 15
files commit 2 edits already failed `nxstyle` on the base commit, which means
commit 2 alone could never pass CI.
I measured this on a clean worktree at the base commit, with `nxstyle`
rebuilt
from source, so this is not a stale-binary artifact:
```text
$ cd /tmp/baseline/nuttx # git worktree add /tmp/baseline/nuttx 9fdcbb56fbb
$ cd tools && make -f Makefile.host nxstyle && cd ..
$ ./tools/nxstyle arch/arm/src/imx9/imx9_irq.c
/tmp/baseline/nuttx/arch/arm/src/imx9/imx9_irq.c:238:11: error: Bad alignment
/tmp/baseline/nuttx/arch/arm/src/imx9/imx9_irq.c:239:11: error: Bad alignment
/tmp/baseline/nuttx/arch/arm/src/imx9/imx9_irq.c:245:11: error: Bad alignment
/tmp/baseline/nuttx/arch/arm/src/imx9/imx9_irq.c:246:11: error: Bad alignment
```
The same lines are reported at the base commit and after the fix, i.e. these
are pre-existing violations, not introduced here.
### What is fixed
| Category | Count | Change |
| -------- | ----: | ------ |
| `Bad alignment` | 131 | statements inside `if`-bodies indented with 11
spaces instead of 10 |
| `Statement on same line as 'if'` | 14 | single-line `if` split into brace
blocks |
| `Statement on same line as 'else'` | 2 | `else (cond)` → `else if (cond)` |
| `Missing blank line after declarations` | 1 | blank line added after
`irqstate_t flags;` |
| `Bad right brace alignment` | 1 | the closing brace of `switch` was
indented 8 spaces instead of 4 |
The `Bad alignment` count is 131 checks, and they map to 131 distinct source
lines: 65 `*regaddr` lines and 65 `*bit` lines are re-indented from 11 to 10
spaces, plus one `*bit` line in `lc823450_irq.c` (line 393) that is
re-indented
from 9 to 10 spaces.
### The one non-cosmetic change
`else (cond)` is not valid C. It is a genuine compile error in
`up_prioritize_irq()` on `efm32` and `eoss3`, hidden behind
`#ifdef CONFIG_ARCH_IRQPRIO`. Measured by extracting the function body from
the
base and fixed revisions and compiling each with `gcc -c`:
Base revision (`9fdcbb56fbb`), `else (irq < EFM32_IRQ_NVECTORS)`:
```text
$ gcc -c -o /dev/null before.c
before.c: In function 'up_prioritize_irq':
before.c:32:34: error: expected ';' before '{' token
32 | else (irq < EFM32_IRQ_NVECTORS)
| ^
| ;
33 | {
| ~
rc=1
```
Fixed revision (`0027bdca41d`), `else if (irq < EFM32_IRQ_NVECTORS)`:
```text
$ gcc -c -o /dev/null after.c
rc=0
```
So this hunk converts code that could not compile into code that compiles.
All
other hunks are whitespace, brace placement, or a duplicate brace.
### Behaviour impact
Ignoring whitespace, commit 1 changes only 5 files:
```text
$ git diff -w --stat 9fdcbb56fbb 0027bdca41d
arch/arm/src/efm32/efm32_irq.c | 2 +-
arch/arm/src/eoss3/eoss3_irq.c | 2 +-
arch/arm/src/lc823450/lc823450_irq.c | 1 +
.../arm/stm32f3/stm32f334-disco/src/stm32_smps.c | 38
++++++++++++++++++----
.../arm/stm32g4/b-g474e-dpow1/src/stm32_smps.c | 38
++++++++++++++++++----
5 files changed, 65 insertions(+), 16 deletions(-)
```
The 10 `*_irq.c` files contribute zero non-whitespace changes. The two
`stm32_smps.c` files only gain braces around single-line `if` bodies, plus
one
closing brace that moves from 8 to 4 spaces of indentation (the
`Bad right brace alignment` fix), so semantics are unchanged. Brace counts
confirm the structure is intact — each file gains exactly 7 `{` and 7 `}`,
matching its 7 split `if` statements:
```text
$ git diff 9fdcbb56fbb 0027bdca41d -- <file> | \
awk '/^\+/{o+=gsub(/{/,"{"); c+=gsub(/}/,"}")} /^-/{o-=gsub(/{/,"{");
c-=gsub(/}/,"}")} END{print o, c}'
+7 +7 (stm32f334-disco/src/stm32_smps.c)
+7 +7 (b-g474e-dpow1/src/stm32_smps.c)
$ grep -o '{' boards/arm/stm32f3/stm32f334-disco/src/stm32_smps.c | wc -l
# 72
$ grep -o '}' boards/arm/stm32f3/stm32f334-disco/src/stm32_smps.c | wc -l
# 72
base commit: 65 / 65 for both files
```
## Commit 2: nvicpri.h merge
The change is a header relocation plus an include-path migration:
- `arch/arm/include/armv7-m/nvicpri.h` → `arch/arm/include/arm_m/nvicpri.h`
(95% similarity, `git` records it as a rename)
- `arch/arm/include/armv8-m/nvicpri.h` deleted; its content was identical to
the ARMv7-M copy
- `arch/arm/include/armv7-m/irq.h`, `arch/arm/include/armv8-m/irq.h`, and 53
source files updated to `#include <arch/arm_m/nvicpri.h>`
File breakdown over the 57 changed paths:
```text
arch/arm/include/ 4 nvicpri.h (rename), armv8-m/nvicpri.h (delete),
armv7-m/irq.h, armv8-m/irq.h
arch/arm/src/ 46 architecture / chip sources
boards/ 7 board sources
```
No macro value or interrupt-priority semantic is changed. ARMv6-M is not
affected (see the note below).
### Note on `armv6-m`
The subject mentions `armv6/7/8-m`, but `armv6-m` is not actually part of
this
merge. There is no `arch/arm/include/armv6-m/nvicpri.h`, and commit 2 neither
adds nor removes one. `arch/arm/include/armv6-m/irq.h` does not include
`nvicpri.h` either; ARMv6-M chips define `NVIC_SYSH_PRIORITY_DEFAULT` and the
related macros directly in their own `chip.h` (`stm32f0`, `stm32g0`,
`stm32l0`,
`nrf52`, `rp2040`, ...). Across `arch/arm/include/*/chip.h` there are 66 such
definitions, none of which this PR touches:
```text
$ for c in stm32f0 stm32g0 stm32l0 nrf52 rp2040; do
> printf '%-10s nvicpri=%s selfdefine=%s\n' $c \
> "$(grep -c nvicpri arch/arm/include/$c/chip.h)" \
> "$(grep -c 'define NVIC_SYSH_PRIORITY_DEFAULT'
arch/arm/include/$c/chip.h)"
> done
stm32f0 nvicpri=0 selfdefine=1
stm32g0 nvicpri=0 selfdefine=1
stm32l0 nvicpri=0 selfdefine=1
nrf52 nvicpri=0 selfdefine=1
rp2040 nvicpri=0 selfdefine=1
```
So this commit is effectively an ARMv7-M / ARMv8-M merge. The subject line is
the original author's wording and is left as-is; worth confirming with the
author whether `armv6` should be dropped from it.
### Duplicate include fixed during review
The first version of commit 2 replaced the `nvicpri.h` include line in
`arch/arm/src/eoss3/eoss3_irq.c` with `<nuttx/irq.h>`, producing:
```c
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h> /* duplicate */
#include <arch/arm_m/nvicpri.h>
```
That duplicate is removed and the include now points at the new header.
Verified by diffing against the reviewed file set:
```text
$ diff arch/arm/src/eoss3/eoss3_irq.c <reviewed copy>
36d35
< #include <nuttx/irq.h>
```
## Testing
All commands were executed from the `nuttx` repository root, on
`apache_20261119_2` at `be0b6610012fda93843c3c621756d0c3c71c1401`.
### Whitespace check
```text
$ MB=$(git merge-base apache/master HEAD); echo $MB
9fdcbb56fbb3b00f97cdbea779156168663cdc18
$ git diff --check $MB..HEAD
rc=0
```
### Checkpatch, whole PR range (equivalent to the Check workflow)
CI computes `commits="$(git merge-base origin/<base_ref> HEAD)..HEAD"`, so
the
range below is the same range CI evaluates.
```text
$ ./tools/checkpatch.sh -c -u -m -g $MB..HEAD
Used config files:
1: .codespellrc
✔️ All checks pass.
rc=0
```
### Checkpatch, each commit individually
```text
### 0027bdca41da8d6fa849c19195540c698f701e3f
Used config files:
1: .codespellrc
✔️ All checks pass.
rc=0
### be0b6610012fda93843c3c621756d0c3c71c1401
✔️ All checks pass.
rc=0
```
### nxstyle, per file (base commit → HEAD)
Measured with an `nxstyle` rebuilt from source in both trees.
```text
arch/arm/src/efm32/efm32_irq.c 1 -> 0
arch/arm/src/eoss3/eoss3_irq.c 1 -> 0
arch/arm/src/imx9/imx9_irq.c 18 -> 0
arch/arm/src/kinetis/kinetis_irq.c 8 -> 0
arch/arm/src/lc823450/lc823450_irq.c 8 -> 0
arch/arm/src/lpc17xx_40xx/lpc17_40_irq.c 4 -> 0
arch/arm/src/mcx-nxxx/nxxx_irq.c 14 -> 0
arch/arm/src/mx8mp/mx8mp_irq.c 8 -> 0
arch/arm/src/sam34/sam_irq.c 12 -> 0
arch/arm/src/samd5e5/sam_irq.c 30 -> 0
arch/arm/src/samv7/sam_irq.c 12 -> 0
arch/arm/src/tiva/common/tiva_irq.c 10 -> 0
arch/arm/src/xmc4/xmc4_irq.c 8 -> 0
boards/arm/stm32f3/stm32f334-disco/src/stm32_smps.c 7 -> 0
boards/arm/stm32g4/b-g474e-dpow1/src/stm32_smps.c 8 -> 0
total 149 -> 0
```
### Note on the `Make.defs` / `.config` message
Running `checkpatch.sh` in a tree where `.config` has been removed prints:
```text
/home/hujun5/work/ssd/online_nuttx/nuttx/tools/../Make.defs:23:
/home/hujun5/work/ssd/online_nuttx/nuttx/tools/../.config: 没有那个文件或目录
make: *** 没有规则可制作目标".../.config"。 停止。
```
This is local environment noise, not a failure of this PR:
- `checkpatch.sh:497` runs `make -C tools -f Makefile.host nxstyle` on every
invocation.
- `tools/Makefile.host:24` has `-include $(TOPDIR)/Make.defs`, and the
developer tree had a generated `Make.defs` symlink whose line 23 is
`include $(TOPDIR)/.config`. With `.config` deleted, that `include` is
fatal
and `make` exits 2.
- The already-built `tools/nxstyle` binary is reused, so linting still runs
and
the script still returns 0.
Verified by temporarily removing the generated `Make.defs`: `make rc=0` and
the
rebuilt `nxstyle` has the same md5 (`c599dd83eb19efe5934b7bedffe7e052`) as
the
existing one, so no stale-binary risk. Both `Make.defs` and `.config` are
listed in `.gitignore` (lines 65 and 49) and are not part of the PR.
### Not run
`CONFIG_ARCH_IRQPRIO` builds for `efm32` and `eoss3` were **not** executed —
there is no matching board configuration and cross toolchain in this
environment. The evidence for the `else (cond)` hunk is the isolated `gcc -c`
comparison above (`rc=1` → `rc=0`), not a full firmware build. Whoever has an
`efm32` or `eoss3` toolchain should confirm with a defconfig that enables
`CONFIG_ARCH_IRQPRIO`.
## Checklist
- [x] `git diff --check` clean
- [x] `checkpatch.sh -c -u -m -g <merge-base>..HEAD` passes
- [x] each commit passes `checkpatch.sh` individually
- [x] `nxstyle` errors in touched files: 149 → 0
- [x] includes the required `Signed-off-by` trailer
- [x] no macro value or priority semantic changed
- [ ] `CONFIG_ARCH_IRQPRIO` build on `efm32` / `eoss3` (not available here)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]