Skip to content

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

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/c902f05603ed
Sep 18, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/c902f05603ed

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

Root Cause Analysis

In DeviceOthers::setInfoFromLshw(), when lshw reports a device driver as "usbfs", the code clears it to an empty string. If the driver is then empty and the device's cfg_avail is "yes", setCanEnable(false) is called, which causes the enable/disable button to disappear from the context menu in TableWidget. This primarily affects USB devices (e.g., cameras) that report "usbfs" as their driver after being disabled — users can no longer re-enable them without rebooting.

Key evidence: DeviceOthers.cpp:46-51 (usbfs clearing → empty driver → setCanEnable(false)), TableWidget.cpp:285-289 (canEnable controls button visibility).

Fix

After clearing the "usbfs" driver value, check if m_Driver is empty AND m_SysPath contains "usb", then set m_Driver = "usb" as a fallback. The isEmpty() guard ensures existing valid drivers are not overwritten. SPDX copyright year updated to "2022 - 2026" in DeviceOthers.cpp. Only DeviceOthers.cpp is modified — DeviceOthers.h is not touched.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The usbfs clearing behavior (commit 4cc56848, PMS bug 333969) is preserved — only a fallback value is added for USB devices when driver is empty
  • The isEmpty() guard prevents overwriting valid driver values from lshw
  • All callers of setInfoFromLshw() and setCanEnable() remain compatible: DeviceManager.cpp:1672 (caller), TableWidget.cpp:285-289 (consumer of canEnable)

Business Impact Scope

Affected module: Other Devices management — USB device enable/disable functionality in Device Manager. After the fix, USB devices (cameras, etc.) that report "usbfs" driver will retain their enable/disable button after being disabled. Non-USB devices are unaffected.

Verification Suggestion

Test USB camera disable then re-enable via right-click context menu; verify non-USB other devices are unaffected; confirm usbfs driver values are still filtered from device info display.


根因分析

DeviceOthers::setInfoFromLshw() 中,当 lshw 报告设备驱动为 "usbfs" 时,代码将其清除为空字符串。如果驱动为空且设备 cfg_avail 为 "yes",则调用 setCanEnable(false),导致右键菜单中的启用/禁用按钮消失。这主要影响禁用后报告 "usbfs" 驱动的 USB 设备(如摄像头)——用户无法重新启用,只能重启系统。

关键证据:DeviceOthers.cpp:46-51(usbfs 清除 → 空驱动 → setCanEnable(false)),TableWidget.cpp:285-289(canEnable 控制按钮显示)。

修复方案

清除 "usbfs" 驱动值后,检查 m_Driver 是否为空且 m_SysPath 是否包含 "usb",若是则设置 m_Driver = "usb" 作为回退值。isEmpty() 前置判断确保不会覆盖 lshw 报告的有效驱动值。DeviceOthers.cpp 的 SPDX 版权年份更新为 "2022 - 2026"。仅修改 DeviceOthers.cpp,不修改 DeviceOthers.h

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • usbfs 清除行为(commit 4cc56848,PMS bug 333969)被保留——仅在驱动为空时为 USB 设备添加回退值
  • isEmpty() 前置判断防止覆盖 lshw 报告的有效驱动值
  • setInfoFromLshw()setCanEnable() 的所有调用者均兼容:DeviceManager.cpp:1672(调用方),TableWidget.cpp:285-289(canEnable 消费方)

业务影响范围

受影响模块:其他设备管理——设备管理器中 USB 设备的启用/禁用功能。修复后,报告 "usbfs" 驱动的 USB 设备(摄像头等)在禁用后仍保留启用/禁用按钮。非 USB 设备不受影响。

验证建议

测试 USB 摄像头禁用后通过右键菜单重新启用;验证非 USB 其他设备不受影响;确认 usbfs 驱动值仍被正确过滤不显示。

PMS: BUG-377341

@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.

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 hours and 18 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 17, 2026

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

Reviewer's Guide

Restores enable/disable controls for USB devices that report usbfs after being disabled by replacing the cleared driver with a usb fallback for USB system paths, while preserving the existing usbfs filtering behavior.

Sequence diagram for restoring USB device enable and disable controls

sequenceDiagram
    participant DeviceManager
    participant DeviceOthers
    participant TableWidget

    DeviceManager->>DeviceOthers: setInfoFromLshw(mapInfo)
    DeviceOthers->>DeviceOthers: setAttribute(mapInfo, "logical name", m_LogicalName)
    alt m_Driver is usbfs
        DeviceOthers->>DeviceOthers: m_Driver.clear()
        alt m_SysPath contains usb
            DeviceOthers->>DeviceOthers: m_Driver = "usb"
        end
    end
    alt m_Driver is empty and m_Avail is not yes
        DeviceOthers->>DeviceOthers: setForcedDisplay(true)
    else USB fallback driver is present
        DeviceOthers->>DeviceOthers: setCanEnable(true)
        TableWidget->>TableWidget: Show enable or disable action
    end
Loading

File-Level Changes

Change Details Files
Add a USB-specific driver fallback after filtering out the lshw-reported usbfs value.
  • Preserve the existing usbfs-to-empty filtering behavior.
  • Set the driver to usb when the device system path identifies a USB device, preventing the driver-empty path from disabling enable/disable controls.
  • Leave non-USB device handling and existing availability logic unchanged.
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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 75 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过(有改进建议)
评分详情 总体评分 75 分,大于 70 分通过阈值。代码无安全漏洞,但存在1处逻辑缺陷需要改进:新增的条件判断会无条件覆盖所有USB设备的驱动信息,建议增加 m_Driver.isEmpty() 条件判断。

🔍 详细分析

1. 语法逻辑 ❌

评价: 一般 ❌ 不通过

潜在问题:

  1. deepin-devicemanager/src/DeviceManager/DeviceOthers.cpp:48 - setInfoFromLshw() 函数中新增的 if (m_SysPath.contains("usb")) 条件块无条件覆盖所有USB设备的驱动信息,应增加 m_Driver.isEmpty() 条件判断

建议: 将条件修改为 if (m_Driver.isEmpty() && m_SysPath.contains("usb")),确保仅在驱动被清空后才设置回退值 "usb",避免覆盖设备的真实驱动信息


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. deepin-devicemanager/src/DeviceManager/DeviceOthers.cpp:48 - 新增代码缺少注释说明设置 m_Driver = "usb" 的原因

建议: 在新增代码块前添加注释,说明该逻辑为 USB 设备 usbfs 驱动清除后的回退处理,避免后续维护时产生困惑


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,QString::contains() 操作开销极小,无性能瓶颈


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无安全风险,代码处理的是系统设备信息,不涉及用户输入或外部数据


💡 改进建议代码示例

// 正确的修复方式:仅在驱动为空时设置回退值
if (m_Driver.toLower() == "usbfs")
    m_Driver.clear();
// 仅当驱动被清空后,为USB设备设置回退驱动值,避免覆盖真实驱动
if (m_Driver.isEmpty() && m_SysPath.contains("usb")) {
    m_Driver = "usb";
}

本报告由 AI 代码审查工具自动生成

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_Driver is empty and
   m_SysPath contains "usb", then 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_Driver 是否为空且 m_SysPath
   包含 "usb",若是则设置 m_Driver 为 "usb" 作为回退值,避免驱动为空
3. 影响:USB 设备(摄像头等)禁用后保留启用/禁用按钮;非 USB
   设备不受影响;usbfs 清除逻辑保留(bug 333969 修复不受影响)

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

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

PMS: BUG-377341
@add-uos
add-uos force-pushed the agent/pms-bug-bot/c902f05603ed branch from 711a1bb to 4d21b71 Compare September 18, 2026 02:12
@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 1ebe13f into linuxdeepin:master 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