Skip to content

fix(cpu): Fix CPU vendor info from dmidecode#646

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
add-uos:fix-357919-Fix-CPU-vendor-info-from-dmidecode
Apr 21, 2026
Merged

fix(cpu): Fix CPU vendor info from dmidecode#646
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
add-uos:fix-357919-Fix-CPU-vendor-info-from-dmidecode

Conversation

@add-uos
Copy link
Copy Markdown
Contributor

@add-uos add-uos commented Apr 20, 2026

Add dmidecode manufacturer info to CPU vendor_id field.

从 dmidecode 获取厂商信息并设置到 CPU vendor_id 字段。

Log: 修复 CPU 厂商信息获取
PMS: BUG-357919
Influence: 修复后 CPU 厂商信息将正确显示,提升设备信息准确性。

Summary by Sourcery

Bug Fixes:

  • Correct CPU vendor identification by populating vendor_id from dmidecode Manufacturer when available.

Add dmidecode manufacturer info to CPU vendor_id field.

从 dmidecode 获取厂商信息并设置到 CPU vendor_id 字段。

Log: 修复 CPU 厂商信息获取
PMS: BUG-357919
Influence: 修复后 CPU 厂商信息将正确显示,提升设备信息准确性。
@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

@github-actions
Copy link
Copy Markdown

  • 检测到敏感词dmidecode变动
详情
    {
    "dmidecode": {
        "deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp": [
            "        if (dmidecode.contains(\"Manufacturer\")) {",
            "            baseCPUInfo[\"vendor_id\"] = dmidecode[\"Manufacturer\"];"
        ]
    }
}

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts CPU device generation so that the CPU vendor_id is sourced from dmidecode Manufacturer information when available before computing and setting CPU header info.

Sequence diagram for updated CPU device generation using dmidecode manufacturer

sequenceDiagram
    participant DeviceGenerator
    participant CpuInfoList as CpuInfoList_lsCpu
    participant DmiDecode as DmiDecode_map
    participant CpuHeader as CpuHeaderInfo

    DeviceGenerator->>CpuInfoList: get first CPU map lsCpu.at(0)
    CpuInfoList-->>DeviceGenerator: baseCPUInfo
    alt Manufacturer present in dmidecode
        DeviceGenerator->>DmiDecode: check key Manufacturer
        DmiDecode-->>DeviceGenerator: Manufacturer value
        DeviceGenerator->>DeviceGenerator: set baseCPUInfo[vendor_id] = dmidecode[Manufacturer]
    else Manufacturer missing
        DeviceGenerator->>DeviceGenerator: keep original baseCPUInfo[vendor_id]
    end
    DeviceGenerator->>CpuHeader: calAndSetCpuHeaderInfo(baseCPUInfo, coreNum, logicalNum)
    CpuHeader-->>DeviceGenerator: CPU header info updated
Loading

Class diagram for updated DeviceGenerator CPU vendor handling

classDiagram
    class DeviceGenerator {
        - QList~QMap_QString_QString~~ lsCpu
        - QMap_QString_QString_ dmidecode
        - int coreNum
        - int logicalNum
        + void generatorCpuDevice()
        + void generatorBiosDevice()
        + void calAndSetCpuHeaderInfo(QMap_QString_QString_ cpuInfo, int coreNum, int logicalNum)
    }

    class QMap_QString_QString_ {
        + QString operator_brackets(QString key)
        + bool contains(QString key)
    }

    class QList_QMap_QString_QString__ {
        + int size()
        + QMap_QString_QString_ at(int index)
    }

    DeviceGenerator o-- QList_QMap_QString_QString__ : uses_lsCpu
    DeviceGenerator o-- QMap_QString_QString_ : uses_dmidecode
    QList_QMap_QString_QString__ o-- QMap_QString_QString_ : contains
Loading

File-Level Changes

Change Details Files
Use dmidecode Manufacturer value to override CPU vendor_id before calculating CPU header information.
  • Wrap the existing CPU header calculation in a block that introduces a mutable baseCPUInfo map copied from the first CPU entry.
  • Check if dmidecode contains a Manufacturer key and, if so, set baseCPUInfo["vendor_id"] to that value.
  • Pass the potentially updated baseCPUInfo map into calAndSetCpuHeaderInfo instead of the original lsCpu.at(0).
deepin-devicemanager/src/GenerateDevice/DeviceGenerator.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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • When overriding vendor_id from dmidecode, consider only doing so if dmidecode["Manufacturer"] is non-empty to avoid replacing a valid lsCpu vendor value with an empty string.
  • To avoid unnecessary copies, you could pass a const reference to the original lsCpu.at(0) into calAndSetCpuHeaderInfo and only clone/mutate a local map when dmidecode actually provides a manufacturer override.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When overriding `vendor_id` from `dmidecode`, consider only doing so if `dmidecode["Manufacturer"]` is non-empty to avoid replacing a valid `lsCpu` vendor value with an empty string.
- To avoid unnecessary copies, you could pass a const reference to the original `lsCpu.at(0)` into `calAndSetCpuHeaderInfo` and only clone/mutate a local map when `dmidecode` actually provides a manufacturer override.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码主要对 DeviceGenerator::generatorCpuDevice() 函数进行了修改,目的是在计算和设置 CPU 头部信息之前,尝试从 dmidecode 数据中获取并覆盖 CPU 的厂商信息(vendor_id)。

以下是对该 diff 的详细审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面:

1. 语法逻辑

  • 逻辑正确性:修改后的逻辑是合理的。它首先获取列表中的第一个 CPU 信息(针对单物理 CPU 环境),然后检查 dmidecode 中是否存在 "Manufacturer" 键。如果存在,则用该值更新 CPU 信息中的 "vendor_id"。最后将合并后的信息传递给处理函数。这符合代码注释中提到的“单物理CPU”的逻辑假设。
  • 数据一致性:逻辑上假设 dmidecode 中的 "Manufacturer" 字段比 lsCpu 中解析出的 "vendor_id" 更准确或更优先。通常 dmidecode 提供的 BIOS/DMI 级别的硬件信息较为底层,这种替换逻辑在业务上是通的。

2. 代码质量

  • 可读性与命名
    • 变量名 baseCPUInfo 命名清晰,表明这是一个基础信息字典。
    • 代码缩进和格式规范,符合 C++ 风格。
  • 健壮性
    • 潜在的数据类型问题:代码中 lsCpu 的元素类型被假定为 QMap<QString, QString>(通过 auto 推导或上下文),并且 dmidecode 也是同类型。如果 dmidecode 的 value 类型不是 QString(例如是 QVariant),直接赋值给 baseCPUInfo["vendor_id"] 可能会导致编译错误或隐式转换。建议确认 dmidecode 的类型定义。
    • 键名硬编码:字符串 "Manufacturer" 和 "vendor_id" 是硬编码的。如果项目中这些键名经常使用,建议定义为 static const QString 常量,以避免拼写错误。

3. 代码性能

  • 拷贝开销QMap<QString, QString> baseCPUInfo = lsCpu.at(0); 这行代码触发了 QMap值拷贝(深拷贝)。QMap 的拷贝操作涉及分配内存和复制所有键值对,如果 map 中数据量较大,会有一定的性能开销。
    • 改进建议:如果 calAndSetCpuHeaderInfo 函数允许接收 const QMap<QString, QString>&(常量引用),建议直接传递 lsCpu.at(0),并在该函数内部处理逻辑,或者使用 std::move(如果 lsCpu 中的元素不再需要被原样保留)。不过,考虑到这是在初始化阶段执行一次,且 CPU 信息条目通常有限,性能影响可以忽略不计。

4. 代码安全

  • 边界检查:代码保留了 if (lsCpu.size() > 0) 的检查,这非常好,防止了空列表导致的越界访问(at(0))。
  • 键值存在性检查dmidecode.contains("Manufacturer") 确保了在访问键之前进行检查,避免了 QMap 插入空键或默认值的风险。
  • 数据源信任:代码信任 dmidecode 中的数据是合法的。如果 "Manufacturer" 的值包含恶意构造的超长字符串或特殊字符,可能会影响后续显示或处理。虽然对于系统硬件信息工具来说风险较低,但在 calAndSetCpuHeaderInfo 中处理字符串时应注意截断或转义。

综合改进建议

为了提高代码的健壮性和可维护性,建议对代码进行微调:

// 建议在类或头文件中定义常量,避免魔法字符串
// static const QString KEY_MANUFACTURER = "Manufacturer";
// static const QString KEY_VENDOR_ID = "vendor_id";

void DeviceGenerator::generatorCpuDevice()
{
    // ... 前面的代码 ...

    if (lsCpu.size() > 0) {
        // 使用引用避免不必要的拷贝,前提是后续不修改原数据
        // 如果 calAndSetCpuHeaderInfo 需要修改 map,则必须保留拷贝
        QMap<QString, QString> baseCPUInfo = lsCpu.at(0);
        
        // 检查 dmidecode 中是否有更权威的厂商信息
        if (dmidecode.contains("Manufacturer")) {
            // 直接赋值,如果 key 已存在则覆盖
            baseCPUInfo["vendor_id"] = dmidecode["Manufacturer"];
        }
        
        calAndSetCpuHeaderInfo(baseCPUInfo, coreNum, logicalNum);
    }
}

总结:这段代码修改逻辑清晰,安全性良好,主要改进点在于关注 QMap 拷贝带来的微小性能损耗以及键名的常量化管理。整体上是一个合格的补丁。

@add-uos
Copy link
Copy Markdown
Contributor Author

add-uos commented Apr 21, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Apr 21, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 87e495f into linuxdeepin:master Apr 21, 2026
21 of 22 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.

2 participants