You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!
为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).
Use workflow from 保持默认分支(通常为 master)
Keep the default branch (usually master) in Use workflow from
在 branch 输入框填写 PR 分支 fix/ofw-phandle-hash-overflow
Enter PR branch fix/ofw-phandle-hash-overflow in the branch field
设置需排除的文件/目录(目录请以"/"结尾)
Set files/directories to exclude (directories should end with "/")
等待工作流完成 | Wait for the workflow to complete
格式化后的代码将作为独立提交推送至你的分支。
The formatting changes will be pushed to your branch as a separate commit.
完成后,提交将自动更新至 fix/ofw-phandle-hash-overflow 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the fix/ofw-phandle-hash-overflow branch automatically, and the related Pull Request will be updated.
如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
ofw_phandle_hash_reset()分配 phandle 表时使用了max - min,但查找时的下标是phandle - min。当 phandle 等于范围上限时,会访问到分配区域之外。另外,扩容时直接把旧的 phandle 上限
old_max当成数组下标来清零,没有减去起始值。当起始 phandle 不是 1 时,清零位置不正确,可能越界或漏掉新增表项。你的解决方案是什么 (what is your solution)
分配数量改为
max - min + 1,包含范围的两个端点。扩容时根据old_max - old_min + 1计算旧表项数量,从旧表末尾开始清零新增区域。在 Linux PC 上提取修复前后的原函数,使用 GCC 和 AddressSanitizer / UndefinedBehaviorSanitizer 做了函数级验证,内存分配接口用主机的 calloc/realloc 模拟:
共 6 个用例,修复前均触发 AddressSanitizer 堆越界报告,修复后全部通过。随后在 QEMU AArch64 virt 上完成 BSP 编译和启动验证,结果如下。
请提供验证的bsp和config (provide the config and bsp)
bsp/qemu-virt64-aarch64,QEMU 6.2.0,AArch64 virt,4 核,128 MB 内存。CONFIG_RT_USING_OFW=y、CONFIG_RT_USING_SMP=y、CONFIG_RT_CPUS_NR=4、CONFIG_RT_USING_MEMHEAP_AS_HEAP=y。QEMU 中增加了临时测试代码,将修复后的分配函数原样提取,仅重命名函数并使用独立的表状态,调用 RT-Thread 的内存分配接口,避免影响系统正在使用的 phandle 表。同时遍历实际设备树,调用
rt_ofw_find_node_by_phandle()检查返回节点是否一致。测试代码不包含在本次提交中。系统正常进入 MSH,未出现测试断言失败。本次未进行实板验证。
QEMU 验证命令及临时测试代码(AI 辅助生成)
将下方代码保存为 BSP 的
applications/phandle_verify.c,在 BSP 目录执行(RTT_EXEC_PATH指向自己的 AArch64 bare-metal 工具链):测试代码:
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up