rockchip: fix race condition and NULL ptr deref in PCIe threaded probe#9561
rockchip: fix race condition and NULL ptr deref in PCIe threaded probe#9561AlomeProg wants to merge 3 commits intoarmbian:mainfrom
Conversation
Signed-off-by: AlomeProg <alomeprog@gmail.com>
📝 WalkthroughWalkthroughReplaces a boolean probe-completion flag with a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the tone of the review comments and chat replies.Configure the |
Hey @AlomeProg! 👋Thanks for submitting your first pull request to the Armbian project — we're excited to have you contributing! 🧡 If you'd like to stay informed about project updates or collaborate more closely with the team, Also, don’t forget to ⭐ star the repo if you haven’t already — and welcome aboard! 🚀 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@patch/kernel/rk35xx-vendor-6.1/fix-threaded-init.patch`:
- Around line 94-102: The loop condition fix is correct (change
time_before(start, start + timeout) to time_before(jiffies, start + timeout)),
but the indentation on the while body (lines with set_current_state,
schedule_timeout, rk_pcie = dev_get_drvdata) contains mixed space+tab; update
those lines to use consistent tabs to match surrounding code style and avoid
checkpatch.pl warnings, ensuring the block under the while (references: rk_pcie,
time_before, jiffies, start, timeout, dev_get_drvdata) is indented uniformly.
- Around line 34-36: The indentation for the new struct field is using spaces
instead of the kernel-required tab; update the declaration of struct completion
probe_done so its leading indentation is a single tab (matching the surrounding
fields) and ensure alignment with the existing bool probe_ok field (symbols:
probe_ok, probe_done) to satisfy kernel coding style and avoid checkpatch.pl
warnings.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fa8268f2-a4f8-4813-ac4c-ee71a05da668
📒 Files selected for processing (1)
patch/kernel/rk35xx-vendor-6.1/fix-threaded-init.patch
There was a problem hiding this comment.
🧹 Nitpick comments (1)
patch/kernel/rk35xx-vendor-6.1/fix-threaded-init.patch (1)
48-49: Good placement of init_completion, but fix indentation.The initialization is correctly placed immediately after the allocation check, ensuring
probe_doneis initialized before any error path that could callcomplete_all(). However, lines 48-49 use spaces instead of tabs for indentation.Proposed fix
Ensure the added lines use a single tab character for indentation to match kernel coding style.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@patch/kernel/rk35xx-vendor-6.1/fix-threaded-init.patch` around lines 48 - 49, The new init_completion call for rk_pcie->probe_done is correctly placed but is indented with spaces; update the added line so it uses a single tab character for indentation to match kernel style (adjust the line containing init_completion(&rk_pcie->probe_done);), ensuring the rest of the surrounding block keeps tab-based alignment with neighboring statements.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@patch/kernel/rk35xx-vendor-6.1/fix-threaded-init.patch`:
- Around line 48-49: The new init_completion call for rk_pcie->probe_done is
correctly placed but is indented with spaces; update the added line so it uses a
single tab character for indentation to match kernel style (adjust the line
containing init_completion(&rk_pcie->probe_done);), ensuring the rest of the
surrounding block keeps tab-based alignment with neighboring statements.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c432ce02-9fea-47f9-9550-73c38b8532ad
📒 Files selected for processing (1)
patch/kernel/rk35xx-vendor-6.1/fix-threaded-init.patch
|
Since we have our own rockchip bsp linux repo, you may want to pr directly against it: https://github.com/armbian/linux-rockchip |
|
Thanks for the quick reply. I created a PR with my changes in linux-rockchip, here is the link: "armbian/linux-rockchip#458". I think it's worth closing this pull request? |
Description
This PR adds a patch to fix a critical kernel panic in the Rockchip PCIe driver (pcie-dw-rockchip.c) occurring on threaded initialization failure.
Documentation summary for feature / change
When CONFIG_PCIE_RK_THREADED_INIT is enabled, a race condition exists between the probe and remove paths. If the hardware initialization fails (e.g., power supply issues or PHY errors), rk_pcie_remove may execute concurrently with the error handling path in the probe thread.
The original implementation had multiple flaws:
My solution:
The patch refactors the synchronization mechanism using standard kernel APIs:
Testing
[x] Tested on RK3588 platform.
[x] Verified that the kernel boots successfully.
[x] Verified that no regression is introduced for successful probe scenarios.
dmesg log
Summary by CodeRabbit