[drivers][i2c] Serialize bus control with transfers - #11820
manyangshen wants to merge 1 commit into
Conversation
Hold the bus mutex while dispatching control commands and changing max_hz. Use a common unlock path and propagate mutex errors as in rt_i2c_transfer. Document the thread-context requirement. Fixes RT-Thread#11524
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
🏷️ Tag: components_driver_i2cReviewers: @wdfk-prog Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-09-22 18:48 CST)
📝 Review Instructions
|
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
96a8233 to
194fa66
Compare
wdfk-prog
left a comment
There was a problem hiding this comment.
LGTM
- 虽然不一定所有的BSP自定义的control都是需要互斥保护的;但是control确实是需要加锁的,由bsp内部加锁也不合适;所以是得加锁保护更好些
|
这组修复已准备好进入正式评审:本 PR 以及 #11821、#11822、#11823、#11824、#11825、#11826。 我重新检查了各 PR 的当前提交,7 组主机回归测试、修改行 clang-format 和 git diff --check 均通过;PM 覆盖 4 种配置,OpenAMP 覆盖两份 BSP 实现。#11823 的 static/局部缓冲区问题也已在对应评审线程回复并补做交错调用对照验证。目标板和上游完整 CI 的验证范围仍以各 PR 描述为准。 目前各 PR 的 CLA 均已通过,但上游 Actions 显示 action_required,等待维护者批准运行。烦请有权限的维护者批准这些待运行的工作流,并继续评审。如有测试失败或修改意见,我会继续跟进。谢谢! |
拉取/合并请求描述:(PR description)
rt_i2c_control() can change the controller configuration while rt_i2c_transfer() is using the bus. Take the same bus mutex around control commands, including SET_MAX_HZ, and release it through a common exit path. Error handling follows rt_i2c_transfer(); the API documentation now states that control requires thread context.
Fixes #11524.
Validation
GCC 16.1 compiled the complete I2C core and device wrapper against repository headers. Host tests with a pthread mutex adapter pass concurrent transfer/control combinations, control/control, max_hz updates, lock and callback errors, and a nested control-to-transfer call. The unpatched source fails the regression suite.
Configuration: RT_USING_I2C, RT_USING_DEVICE_OPS, RT_USING_MUTEX and RT_USING_SEMAPHORE. Changed-line clang-format and git diff --check pass. No target BSP, QEMU or I2C hardware test was run; the host adapter does not test RT-Thread priority inheritance.
当前拉取/合并请求的状态 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