Skip to content

fix: restore USB device enable/disable after driver cleared - #773

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:develop/eagle
Sep 18, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:develop/eagle

Conversation

@add-uos

@add-uos add-uos commented Sep 18, 2026

Copy link
Copy Markdown
Contributor
  1. Root cause: setInfoFromLshw() clears driver when lshw reports "usbfs", leaving it empty; empty driver plus avail=="yes" triggers setCanEnable(false), hiding the enable/disable button in context menu
  2. Fix: after clearing usbfs driver, check if m_SysPath contains "usb" and set m_Driver to "usb" as fallback, preventing the empty-driver condition
  3. Impact: USB devices (cameras, etc.) retain enable/disable button after being disabled; non-USB devices unaffected; usbfs clearing logic preserved (bug 333969 fix intact)

Log: Fix USB device unable to re-enable after being disabled

Influence:

  1. Test USB camera disable then re-enable via context menu
  2. Test non-USB other devices display and enable/disable behavior
  3. Verify usbfs driver values are still filtered from display

fix: 修复USB设备禁用后无法再次启用的问题

  1. 根因:setInfoFromLshw() 在 lshw 报告驱动为 "usbfs" 时清除驱动 值,导致驱动为空;空驱动且 avail 为 "yes" 时触发 setCanEnable(false),右键菜单中启用/禁用按钮消失
  2. 方案:清除 usbfs 驱动后,检查 m_SysPath 是否包含 "usb", 若是则设置 m_Driver 为 "usb" 作为回退值,避免驱动为空
  3. 影响:USB 设备(摄像头等)禁用后保留启用/禁用按钮;非 USB 设备不受影响;usbfs 清除逻辑保留(bug 333969 修复不受影响)

Log: 修复USB设备禁用后无法再次启用的问题

Influence:

  1. 测试USB摄像头禁用后通过右键菜单重新启用
  2. 测试非USB其他设备的显示和启用/禁用功能
  3. 验证usbfs驱动值仍被正确过滤不显示

PMS: BUG-377341

Summary by Sourcery

Bug Fixes:

  • Restore USB device enable/disable controls after the device driver is cleared from lshw output.

1. Root cause: setInfoFromLshw() clears driver when lshw reports
   "usbfs", leaving it empty; empty driver plus avail=="yes" triggers
   setCanEnable(false), hiding the enable/disable button in context
   menu
2. Fix: after clearing usbfs driver, check if m_SysPath contains
   "usb" and set m_Driver to "usb" as fallback, preventing the
   empty-driver condition
3. Impact: USB devices (cameras, etc.) retain enable/disable button
   after being disabled; non-USB devices unaffected; usbfs clearing
   logic preserved (bug 333969 fix intact)

Log: Fix USB device unable to re-enable after being disabled

Influence:
1. Test USB camera disable then re-enable via context menu
2. Test non-USB other devices display and enable/disable behavior
3. Verify usbfs driver values are still filtered from display

fix: 修复USB设备禁用后无法再次启用的问题

1. 根因:setInfoFromLshw() 在 lshw 报告驱动为 "usbfs" 时清除驱动
   值,导致驱动为空;空驱动且 avail 为 "yes" 时触发
   setCanEnable(false),右键菜单中启用/禁用按钮消失
2. 方案:清除 usbfs 驱动后,检查 m_SysPath 是否包含 "usb",
   若是则设置 m_Driver 为 "usb" 作为回退值,避免驱动为空
3. 影响:USB 设备(摄像头等)禁用后保留启用/禁用按钮;非 USB
   设备不受影响;usbfs 清除逻辑保留(bug 333969 修复不受影响)

Log: 修复USB设备禁用后无法再次启用的问题

Influence:
1. 测试USB摄像头禁用后通过右键菜单重新启用
2. 测试非USB其他设备的显示和启用/禁用功能
3. 验证usbfs驱动值仍被正确过滤不显示

PMS: BUG-377341
@sourcery-ai

sourcery-ai Bot commented Sep 18, 2026

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

Reviewer's Guide

Updates USB device driver handling in setInfoFromLshw(): usbfs remains filtered, but USB devices receive a fallback driver value based on their sysfs path, preserving their enable/disable context-menu action after being disabled while leaving non-USB behavior unchanged.

Flow diagram for USB driver fallback handling

flowchart TD
    A[setInfoFromLshw] --> B{Driver is usbfs?}
    B -- Yes --> C[Clear m_Driver]
    B -- No --> D{m_Driver is empty and sysfs path contains usb?}
    C --> D
    D -- Yes --> E[Set m_Driver to usb]
    D -- No --> F{m_Driver is empty and avail is not yes?}
    E --> G[Retain enable/disable action]
    F -- Yes --> H[setForcedDisplay and setCanEnable false]
    F -- No --> G
    C -.-> I[usbfs remains hidden]
Loading

File-Level Changes

Change Details Files
Restore USB device enable/disable capability when lshw reports the filtered usbfs driver.
  • Continue clearing usbfs so it is not displayed as a real driver.
  • Use the USB sysfs path to assign a fallback usb driver when the cleared value is empty.
  • Prevent the empty-driver availability logic from disabling the context-menu action for USB devices.
deepin-devicemanager/src/DeviceManager/DeviceOthers.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/src/DeviceManager/DeviceOthers.cpp" line_range="38-42" />
<code_context>
     setAttribute(mapInfo, "logical name", m_LogicalName);
     if (m_Driver.toLower() == "usbfs")
         m_Driver.clear();
+    if (m_Driver.isEmpty() && m_SysPath.contains("usb")) {
+    	m_Driver = "usb";
+    }
     if(m_Driver.isEmpty() && !m_Avail.compare("yes", Qt::CaseInsensitive)){
         setForcedDisplay(true);
</code_context>
<issue_to_address>
**issue (broader_impact):** The fallback runs for every USB device with an empty driver, not only when the driver was cleared from `usbfs`. A genuinely driverless USB device is therefore assigned the synthetic `usb` driver, bypassing the later unavailable-device handling and causing it to remain available with enable/disable actions even though no driver is attached.

**Triggers:** When lshw reports no driver for a USB device and `m_Avail` is not `yes`.

**Suggested fix:** Restrict the fallback to the `usbfs`-clearing path, for example by recording whether the original driver was `usbfs` before clearing it.

```suggestion
    const bool wasUsbfs = m_Driver.toLower() == "usbfs";
    if (wasUsbfs)
        m_Driver.clear();
    if (wasUsbfs && m_SysPath.contains("usb")) {
    	m_Driver = "usb";
    }
```
</issue_to_address>

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

Comment on lines 38 to +42
if (m_Driver.toLower() == "usbfs")
m_Driver.clear();
if (m_Driver.isEmpty() && m_SysPath.contains("usb")) {
m_Driver = "usb";
}

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 (broader_impact): The fallback runs for every USB device with an empty driver, not only when the driver was cleared from usbfs. A genuinely driverless USB device is therefore assigned the synthetic usb driver, bypassing the later unavailable-device handling and causing it to remain available with enable/disable actions even though no driver is attached.

Triggers: When lshw reports no driver for a USB device and m_Avail is not yes.

Suggested fix: Restrict the fallback to the usbfs-clearing path, for example by recording whether the original driver was usbfs before clearing it.

Suggested change
if (m_Driver.toLower() == "usbfs")
m_Driver.clear();
if (m_Driver.isEmpty() && m_SysPath.contains("usb")) {
m_Driver = "usb";
}
const bool wasUsbfs = m_Driver.toLower() == "usbfs";
if (wasUsbfs)
m_Driver.clear();
if (wasUsbfs && m_SysPath.contains("usb")) {
m_Driver = "usb";
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@add-uos

add-uos commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit d1dfd30 into linuxdeepin:develop/eagle Sep 18, 2026
17 checks passed
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.

3 participants