fix: add delay between USB authorized disable and re-enable - #756
GongHeng2017 wants to merge 1 commit into
Conversation
1. Root cause: authorizedEnable() writes 0 then 1 to parent USB authorized file without any delay, kernel USB subsystem cannot complete deinitialization before reinitialization starts 2. Fix: insert QThread::msleep(800) between writing 0 and writing 1 to ensure USB subsystem finishes deinitialization on ARM platforms 3. Impact: only affects USB device enable path, adds ~800ms latency to enable operation, no change to disable path or function signature Log: fix USB device unusable after disable then enable on ARM Influence: 1. Test USB mouse disable then enable on Phytom D3000M 2. Test USB device disable then enable on x86 platform 3. Verify no regression on other USB device enable/disable fix: 修复USB设备禁用后启用无法使用的问题 1. 根因:authorizedEnable() 对父级USB authorized文件执行无延迟的 0→1切换,内核USB子系统来不及完成去初始化即开始重新初始化 2. 方案:在写0和写1之间插入QThread::msleep(800)延迟,确保USB 子系统在ARM平台上完成去初始化后再重新启用 3. 影响:仅影响USB设备启用路径,启用操作增加约800ms延迟, 不影响禁用路径和函数签名 Log: 修复飞腾D3000M上USB设备禁用后启用无法使用的问题 Influence: 1. 在飞腾D3000M上测试USB鼠标禁用后启用 2. 在x86平台上测试USB设备禁用后启用 3. 验证其他USB设备启用禁用无回归 PMS: BUG-341577
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe PR fixes USB devices that fail to recover after an authorized disable/enable cycle by allowing the kernel USB subsystem 800 ms to complete deinitialization before re-enabling the parent device. Sequence diagram for delayed USB authorized re-enablesequenceDiagram
participant ControlInterface
participant AuthorizedFile
participant KernelUSB
ControlInterface->>AuthorizedFile: open(QIODevice::ReadWrite)
ControlInterface->>AuthorizedFile: write("0")
AuthorizedFile->>KernelUSB: disable parent USB device
ControlInterface->>ControlInterface: QThread::msleep(800)
ControlInterface->>AuthorizedFile: open(QIODevice::ReadWrite)
ControlInterface->>AuthorizedFile: write("1")
AuthorizedFile->>KernelUSB: re-enable parent USB device
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cpp" line_range="362" />
<code_context>
fpop.write("0");
fpop.close();
+ QThread::msleep(800);
+
// 第三步
</code_context>
<issue_to_address>
**issue (bug_risk):** `QThread::msleep(800)` blocks the single thread that owns `ControlInterface` and runs the D-Bus event loop, so other D-Bus requests and queued signals cannot be processed during the USB re-enable delay.
**Triggers:** When another device-control request or queued event arrives during USB device re-enabling.
**Suggested fix:** Perform the delayed re-enable in a worker thread or restructure the operation as an asynchronous state machine so the D-Bus event loop remains responsive.
</issue_to_address>| fpop.write("0"); | ||
| fpop.close(); | ||
|
|
||
| QThread::msleep(800); |
There was a problem hiding this comment.
issue (bug_risk): QThread::msleep(800) blocks the single thread that owns ControlInterface and runs the D-Bus event loop, so other D-Bus requests and queued signals cannot be processed during the USB re-enable delay.
Triggers: When another device-control request or queued event arrives during USB device re-enabling.
Suggested fix: Perform the delayed re-enable in a worker thread or restructure the operation as an asynchronous state machine so the D-Bus event loop remains responsive.
修复说明
PMS Bug #341577
问题:飞腾D3000M RTM 通用镜像测试中,设备管理器鼠标禁用后启用,仍无法使用,需重新拔插才恢复正常。
根因
ControlInterface::authorizedEnable()启用分支对父级 USB 设备 authorized 文件执行无延迟的 0→1 快速切换。第二步(写"0"禁用)与第三步(写"1"启用)之间无延迟,内核 USB 子系统来不及完成去初始化即重新初始化,在 ARM 平台(飞腾D3000M)上时序差异导致驱动未正确绑定,鼠标不可用。修复方案
在第二步与第三步之间插入
QThread::msleep(800)延迟,确保内核 USB 子系统完成去初始化后再重新启用。改动范围
deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cppSummary by Sourcery
Bug Fixes: