Skip to content

fix: add delay between USB authorized disable and re-enable - #756

Open
GongHeng2017 wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/pms-bug-bot/5211afd8284d
Open

GongHeng2017 wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/pms-bug-bot/5211afd8284d

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

修复说明

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.cpp
  • 改动量:1 file changed, 3 insertions(+)
  • 风险等级:低

Summary by Sourcery

Bug Fixes:

  • Add an 800 ms delay between disabling and re-enabling parent USB devices to ensure USB peripherals, such as mice, recover correctly.

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
@sourcery-ai

sourcery-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The 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-enable

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Add an 800 ms pause between disabling and re-enabling the parent USB device through its authorized sysfs control.
  • Include QThread for the sleep API.
  • Sleep after writing "0" and before reopening the authorized file for the enable step.
deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

fpop.write("0");
fpop.close();

QThread::msleep(800);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant