fix: restore USB device enable/disable after driver cleared - #773
Conversation
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
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates 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 handlingflowchart 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]
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/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>| if (m_Driver.toLower() == "usbfs") | ||
| m_Driver.clear(); | ||
| if (m_Driver.isEmpty() && m_SysPath.contains("usb")) { | ||
| m_Driver = "usb"; | ||
| } |
There was a problem hiding this comment.
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.
| 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"; | |
| } |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
Log: Fix USB device unable to re-enable after being disabled
Influence:
fix: 修复USB设备禁用后无法再次启用的问题
Log: 修复USB设备禁用后无法再次启用的问题
Influence:
PMS: BUG-377341
Summary by Sourcery
Bug Fixes: