Skip to content

fix: remove incorrect SysFS path normalization - #954

Closed
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:fix/ut-def-004-enableutils-path-normalization
Closed

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:fix/ut-def-004-enableutils-path-normalization

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 zeroed the last digit of SysFS paths, corrupting both
    USB device port numbers and interface numbers
  2. Fix: remove the normalization line so SysFS paths retain their
    original values for authorized file access
  3. Impact: multi-interface USB devices no longer have their authorized
    paths overwritten; single-interface behavior unchanged

Log: fix USB device authorized path corruption from path normalization

Influence:

  1. Test disabling USB devices with multi-interface configurations
  2. Verify authorized file paths match actual SysFS paths
  3. Test enabling/disabling single-interface USB devices for regression

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

  1. 根因:path.replace(QRegularExpression("[1-9]$"), "0") 粗暴地将
    SysFS 路径末位数字归零,同时破坏了设备端口号和接口号
  2. 方案:移除归一化行,使 SysFS 路径保持原值用于 authorized
    文件访问
  3. 影响:多接口 USB 设备不再出现 authorized 路径相互覆盖;
    单接口设备行为不变

Log: 修复 USB 设备 authorized 路径因归一化导致被覆盖的问题

Influence:

  1. 测试多接口 USB 设备的禁用功能
  2. 验证 authorized 文件路径与实际 SysFS 路径一致
  3. 测试单接口 USB 设备的启用/禁用以检查回归

Summary by Sourcery

Bug Fixes:

  • Preserve original SysFS paths when disabling devices so authorized file access no longer corrupts USB port or interface identifiers.

1. Root cause: path.replace(QRegularExpression("[1-9]$"), "0")
   blindly zeroed the last digit of SysFS paths, corrupting both
   USB device port numbers and interface numbers
2. Fix: remove the normalization line so SysFS paths retain their
   original values for authorized file access
3. Impact: multi-interface USB devices no longer have their authorized
   paths overwritten; single-interface behavior unchanged

Log: fix USB device authorized path corruption from path normalization

Influence:
1. Test disabling USB devices with multi-interface configurations
2. Verify authorized file paths match actual SysFS paths
3. Test enabling/disabling single-interface USB devices for regression

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

1. 根因:path.replace(QRegularExpression("[1-9]$"), "0") 粗暴地将
   SysFS 路径末位数字归零,同时破坏了设备端口号和接口号
2. 方案:移除归一化行,使 SysFS 路径保持原值用于 authorized
   文件访问
3. 影响:多接口 USB 设备不再出现 authorized 路径相互覆盖;
   单接口设备行为不变

Log: 修复 USB 设备 authorized 路径因归一化导致被覆盖的问题

Influence:
1. 测试多接口 USB 设备的禁用功能
2. 验证 authorized 文件路径与实际 SysFS 路径一致
3. 测试单接口 USB 设备的启用/禁用以检查回归
@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 10 hours and 29 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 from USB device disabling so multi-interface devices retain distinct, actual authorized paths while single-interface behavior remains unchanged.

Sequence diagram for preserving USB SysFS authorized paths

sequenceDiagram
    participant Caller
    participant EnableUtils
    participant SysFS

    Caller->>EnableUtils: disableOutDevice(info)
    EnableUtils->>EnableUtils: mapItem["SysFS ID"]
    EnableUtils->>SysFS: access original SysFS path
    SysFS-->>EnableUtils: authorized file for exact device/interface path
    EnableUtils-->>Caller: device disabled
Loading

File-Level Changes

Change Details Files
Preserve the original SysFS path when disabling non-network devices.
  • Removed the trailing-digit replacement that changed paths ending in 1–9 to 0.
  • Allow authorized-file access to use the exact mapped SysFS path, preserving USB port and interface identifiers.
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.cpp 中 disableOutDevice 函数里错误的 SysFS 路径规范化逻辑(path.replace(QRegularExpression("[1-9]$"), "0")),该逻辑会错误地将 SysFS 路径末尾的数字 1-9 替换为 0,导致设备路径不正确。删除此行代码修复了该问题,变更范围小且明确,四维度均无问题,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: 无


2. 代码质量 ✅

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

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

建议: 可考虑清理删除后残留的多余空行,使代码更紧凑。


3. 代码性能 ✅

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

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

建议: 无


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: 无


💡 改进建议代码示例

// 当前代码已正确:移除错误的路径规范化后,path 保持原始 SysFS ID 值
// 无需额外修复,删除 path.replace(QRegularExpression("[1-9]$"), "0") 即为正确做法
// disableOutDevice 函数中路径获取逻辑(修改后):
// if (mapItem.contains("Path")) {
//     path = mapItem["Path"];
// } else {
//     path = mapItem["SysFS ID"];
// }
// // 路径直接使用,不做错误的末尾数字替换
// 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