Skip to content

fix: remove incorrect SysFS path normalization - #955

Closed
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/07c69eb06fc6
Closed

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/07c69eb06fc6

Conversation

@add-uos

@add-uos add-uos commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

fix: remove incorrect SysFS path normalization

  1. Root cause: path.replace(QRegularExpression("[1-9]$"), "0")
    blindly normalized the last digit of SysFS ID/Device Link to 0,
    collapsing multi-interface USB device paths (e.g. 1-2.3 → 1-2.0)
    and causing authorized file paths to overwrite each other
  2. Fix: remove the incorrect normalization line so each interface
    keeps its original SysFS path for authorized file operations
  3. Impact: multi-interface USB devices are no longer treated as the
    same path; disableOutDevice writes to the correct authorized file
    per interface

Influence:

  1. Test disabling a multi-interface USB device and verify each
    interface gets its own authorized file
  2. Test disabling a single-interface USB device for no regression
  3. Verify network card disable path still works via ioctl

fix: 移除错误的 SysFS 路径归一化

  1. 根因:path.replace(QRegularExpression("[1-9]$"), "0") 盲目将
    SysFS ID/Device Link 末位数字归零,导致多接口 USB 设备路径被
    折叠(如 1-2.3 → 1-2.0),authorized 文件路径相互覆盖
  2. 方案:移除该错误归一化行,使每个接口保留原始 SysFS 路径进行
    authorized 文件操作
  3. 影响:多接口 USB 设备不再被视为同一路径,disableOutDevice
    按接口写入正确的 authorized 文件

Influence:

  1. 测试禁用多接口 USB 设备,验证每个接口写入独立 authorized 文件
  2. 测试禁用单接口 USB 设备,验证无回归
  3. 验证网卡禁用路径仍通过 ioctl 正常工作

Summary by Sourcery

Bug Fixes:

  • Preserve each device interface’s original SysFS path when disabling output devices, preventing multi-interface USB paths from being collapsed and authorized files from being overwritten.

1. Root cause: path.replace(QRegularExpression("[1-9]$"), "0")
   blindly normalized the last digit of SysFS ID/Device Link to 0,
   collapsing multi-interface USB device paths (e.g. 1-2.3 → 1-2.0)
   and causing authorized file paths to overwrite each other
2. Fix: remove the incorrect normalization line so each interface
   keeps its original SysFS path for authorized file operations
3. Impact: multi-interface USB devices are no longer treated as the
   same path; disableOutDevice writes to the correct authorized file
   per interface

Influence:
1. Test disabling a multi-interface USB device and verify each
   interface gets its own authorized file
2. Test disabling a single-interface USB device for no regression
3. Verify network card disable path still works via ioctl

fix: 移除错误的 SysFS 路径归一化

1. 根因:path.replace(QRegularExpression("[1-9]$"), "0") 盲目将
   SysFS ID/Device Link 末位数字归零,导致多接口 USB 设备路径被
   折叠(如 1-2.3 → 1-2.0),authorized 文件路径相互覆盖
2. 方案:移除该错误归一化行,使每个接口保留原始 SysFS 路径进行
   authorized 文件操作
3. 影响:多接口 USB 设备不再被视为同一路径,disableOutDevice
   按接口写入正确的 authorized 文件

Influence:
1. 测试禁用多接口 USB 设备,验证每个接口写入独立 authorized 文件
2. 测试禁用单接口 USB 设备,验证无回归
3. 验证网卡禁用路径仍通过 ioctl 正常工作
@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown

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 9 hours and 42 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

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

Reviewer's Guide

Removes incorrect SysFS path normalization in disableOutDevice, preventing multi-interface USB paths from collapsing onto the same authorized file while leaving network ioctl handling unchanged.

Sequence diagram for per-interface USB device disabling

sequenceDiagram
    participant Caller
    participant EnableUtils
    participant SysFS

    Caller->>EnableUtils: disableOutDevice(info)
    EnableUtils->>EnableUtils: Read SysFS ID or Device Link
    EnableUtils->>SysFS: Write authorized file for original interface path
    SysFS-->>EnableUtils: Interface disabled
Loading

Flow diagram for USB and network device disabling

flowchart TD
    A["disableOutDevice(info)"] --> B{Network device?}
    B -->|Yes| C[ioctl]
    B -->|No| D[Use original SysFS path]
    D --> E[Write interface authorized file]
    E --> F[Disable USB interface]
Loading

File-Level Changes

Change Details Files
Preserve the original SysFS path when disabling devices so authorized-file operations remain interface-specific.
  • Removed the trailing-digit replacement that converted paths such as 1-2.3 to 1-2.0.
  • Retained the existing network-device ioctl branch and downstream disable logic.
deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.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 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交移除了 EnableUtils::disableOutDevice() 中对 SysFS 路径的错误正则归一化处理(将末尾 1-9 数字替换为 0),修复了设备路径被错误修改的 bug。变更简单清晰,仅删除两行代码,无语法错误、无逻辑缺陷、无安全漏洞,四维度均通过。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 本次变更无需额外修复代码示例,删除错误代码即为正确的修复方式。 // 修改后的代码保持 path 变量从 mapItem["SysFS ID"] 获取后直接使用,不做错误归一化: // // void EnableUtils::disableOutDevice(const QString &info) // { //     ... //     } else { //         path = mapItem["SysFS ID"]; //     } // //     // 网卡采用ioctl的方式禁用 //     QRegularExpression reg(REG_ADDRESS); //     ... // }

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

@add-uos add-uos closed this Oct 28, 2026
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.

2 participants