Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Jan 22, 2026

pick from v20

Summary by Sourcery

Adjust CPU and Bluetooth device information handling to improve accuracy and avoid incorrect attribute overrides.

Bug Fixes:

  • Guard CPU core count updates with an additional consistency check between logical CPU values to avoid using incorrect /proc/cpuinfo data.
  • Modify Bluetooth device attribute population to prevent unintended overwriting of the device name and stop exposing the HCI version field from hciconfig.

disable bluetooth failed due to name

log: fix the disable bluetooth failed
bug: https://pms.uniontech.com/bug-view-341783.html
Change-Id: I4495dc67a1480ae3695c253b474e3dd45c11442a
fix from dmidecode get cpu num maybe error

log: fix from dmidecode get cpu num maybe error
bug: https://pms.uniontech.com/bug-view-343951.html
remove hci version attribute setting

pick from: 1d58066

log: remove hci version attribute setting
bug: https://pms.uniontech.com/bug-view-347359.html
Change-Id: I10ee960525c16efa86869f13fbf24d4a06fcde81
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 22, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts CPU core/logical count selection logic to prefer dmidecode data only when /proc/cpuinfo appears inconsistent, and refines Bluetooth device attribute extraction from hciconfig by changing how certain fields are set.

Sequence diagram for updated CPU device generation logic

sequenceDiagram
    participant DG as DeviceGenerator
    participant Proc as ProcCpuinfo
    participant DMI as Dmidecode
    participant DM as DeviceManager

    DG->>Proc: readCpuCoreAndLogicalCounts()
    Proc-->>DG: coreNum, logicalNum

    DG->>DMI: readDmiCpuCoreAndLogicalCounts()
    DMI-->>DG: coreNum_dmi, logicalNum_dmi

    DG->>DG: if coreNum_dmi > coreNum && coreNum_dmi <= 512
    DG->>DG:   if logicalNum != logicalNum_dmi
    DG->>DG:       coreNum = coreNum_dmi

    DG->>DG: if logicalNum_dmi > logicalNum && logicalNum_dmi < 1024
    DG->>DG:     logicalNum = logicalNum_dmi

    DG->>DM: setCpuNum(detectedCpuCount)
    DM-->>DG: ack
Loading

Class diagram for updated DeviceGenerator and DeviceBluetooth

classDiagram
    class DeviceGenerator {
        +void generatorCpuDevice()
        -int coreNum
        -int logicalNum
        -int coreNum_dmi
        -int logicalNum_dmi
    }

    class DeviceManager {
        +static DeviceManager instance()
        +void setCpuNum(int cpuNum)
    }

    class DeviceBluetooth {
        +void setInfoFromHciconfig(QMapQStringQString mapInfo)
        -QString m_Name
        -QString m_Alias
        -QString m_Vendor
        -QString m_Version
    }

    class AttributeHelper {
        +void setAttribute(QMapQStringQString mapInfo, QString key, QString target)
        +void setAttribute(QMapQStringQString mapInfo, QString key, QString target, bool strict)
    }

    DeviceGenerator --> DeviceManager : uses
    DeviceBluetooth --> AttributeHelper : uses
Loading

File-Level Changes

Change Details Files
Refine CPU core and logical processor count derivation using dmidecode as a fallback to /proc/cpuinfo.
  • Add condition to update core count from dmidecode only when dmidecode core count exceeds current core count, is within a valid upper bound, and the logical processor counts disagree between sources.
  • Retain logic to update logical processor count from dmidecode when it exceeds the current value within a valid upper bound.
  • Reorder and group CPU count update logic to emphasize dmidecode as a corrective source rather than unconditional override.
deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp
Adjust Bluetooth device attribute assignment from hciconfig output to better control which fields are set and how.
  • Change the Name attribute assignment to call the attribute helper with an explicit flag disabling some behavior (e.g., formatting or fallback) for this field.
  • Remove setting of the HCI Version attribute from hciconfig parsing, likely to avoid incorrect or redundant version info.
  • Leave Alias and Manufacturer assignments unchanged while simplifying the attribute setup sequence.
deepin-devicemanager/src/DeviceManager/DeviceBluetooth.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

deepin pr auto review

这段'll review the git diff changes and provide feedback on syntax, logic, code quality, performance, and security:

Review of Changes

1. DeviceBluetooth.cpp Changes

Changes Made:

  • Modified setAttribute call for "Name" to include a third parameter false
  • Removed the setAttribute call for "HCI Version"

Analysis:

  • Syntax: The syntax appears correct, assuming setAttribute is a method that accepts an optional third boolean parameter.
  • Logic: The removal of the "HCI Version" attribute suggests this information is no longer needed or is being set elsewhere. The addition of false as the third parameter for "Name" likely changes some behavior of the attribute setting process.
  • Code Quality: Without seeing the full implementation of setAttribute, it's hard to judge the quality impact. The change appears intentional and focused.
  • Performance: No significant performance impact expected from these changes.
  • Security: No security concerns identified.

Recommendations:

  1. Consider adding a comment explaining why the third parameter false is needed for "Name"
  2. If "HCI Version" is being set elsewhere, ensure consistency across the codebase

2. DeviceGenerator.cpp Changes

Changes Made:

  • Reordered the conditional checks for coreNum_dmi and logicalNum_dmi
  • Added an inner condition to check logicalNum != logicalNum_dmi before updating coreNum
  • Added a comment explaining the logic

Analysis:

  • Syntax: The syntax is correct.
  • Logic: The logic now checks if logicalNum_dmi is different from logicalNum before updating coreNum, which adds a dependency between these two values. This might be intentional but needs careful consideration.
  • Code Quality: The added comment helps explain the logic, but the nested condition makes the code slightly more complex.
  • Performance: No significant performance impact.
  • Security: No security concerns identified.

Recommendations:

  1. Consider extracting the complex condition into a separate method with a descriptive name to improve readability
  2. The comment "due to offline policy" is vague - consider expanding it to explain what this policy is
  3. Verify if the dependency between logicalNum and coreNum updates is intentional and correct

General Observations

  1. Both changes appear to be focused on refining how device information is collected and processed.
  2. The changes don't introduce any obvious security vulnerabilities.
  3. The code quality could be improved with more descriptive comments explaining the rationale behind the changes.

Suggested Improvements

For DeviceBluetooth.cpp:

// Use the raw name without any processing (third parameter false)
setAttribute(mapInfo, "Name", m_Name, false);

For DeviceGenerator.cpp:

// Due to offline policy: prefer dmidecode data when available and within valid range
if (coreNum_dmi > coreNum && coreNum_dmi <= 512) {
    // Only update core count if logical counts differ between sources
    if (logicalNum != logicalNum_dmi) {
        coreNum = coreNum_dmi;
    }
}
if (logicalNum_dmi > logicalNum && logicalNum_dmi < 1024) {
    logicalNum = logicalNum_dmi;
}

Alternatively, consider extracting the logic to a separate method:

bool DeviceGenerator::shouldUpdateFromDmi(int dmiValue, int currentValue, int maxValue) {
    return dmiValue > currentValue && dmiValue <= maxValue;
}

// Then use it like:
if (shouldUpdateFromDmi(coreNum_dmi, coreNum, 512)) {
    if (logicalNum != logicalNum_dmi) {
        coreNum = coreNum_dmi;
    }
}
if (shouldUpdateFromDmi(logicalNum_dmi, logicalNum, 1024)) {
    logicalNum = logicalNum_dmi;
}

This improves readability and makes the code more maintainable.

Copy link

@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 found 1 issue, and left some high level feedback:

  • The coreNum_dmi/logicalNum_dmi thresholds (512, 1024) are currently hard-coded; consider extracting them into named constants or a small helper function so the offline policy is easier to understand and maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `coreNum_dmi`/`logicalNum_dmi` thresholds (512, 1024) are currently hard-coded; consider extracting them into named constants or a small helper function so the offline policy is easier to understand and maintain.

## Individual Comments

### Comment 1
<location> `deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp:225-227` </location>
<code_context>
             logicalNum_dmi += dd4["Thread Count"].toInt();
         }
     }
+    if(coreNum_dmi > coreNum && coreNum_dmi <= 512) { //due to offline policy
+    	// If obtaining data from /proc/cpuinfo is incorrect, refer to the content of dmidecode.
+        if (logicalNum != logicalNum_dmi)
+            coreNum = coreNum_dmi;
+    }
</code_context>

<issue_to_address>
**issue (bug_risk):** Reconsider using `logicalNum != logicalNum_dmi` instead of a directional comparison to gate `coreNum` updates.

The previous behavior updated `coreNum` from DMI whenever `coreNum_dmi > coreNum && coreNum_dmi <= 512`, independent of logical CPU counts. Now the update is gated on `logicalNum != logicalNum_dmi`, which also triggers when `logicalNum_dmi < logicalNum`. In that case, you’d override `coreNum` from DMI while still trusting `/proc` for `logicalNum`, mixing sources asymmetrically. If the goal is to fix undercounting in `/proc/cpuinfo`, consider restricting this to `logicalNum_dmi > logicalNum && logicalNum_dmi < 1024` (aligned with the later logical update) or otherwise making the comparison direction explicit.
</issue_to_address>

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.

Comment on lines +225 to +227
if(coreNum_dmi > coreNum && coreNum_dmi <= 512) { //due to offline policy
// If obtaining data from /proc/cpuinfo is incorrect, refer to the content of dmidecode.
if (logicalNum != logicalNum_dmi)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Reconsider using logicalNum != logicalNum_dmi instead of a directional comparison to gate coreNum updates.

The previous behavior updated coreNum from DMI whenever coreNum_dmi > coreNum && coreNum_dmi <= 512, independent of logical CPU counts. Now the update is gated on logicalNum != logicalNum_dmi, which also triggers when logicalNum_dmi < logicalNum. In that case, you’d override coreNum from DMI while still trusting /proc for logicalNum, mixing sources asymmetrically. If the goal is to fix undercounting in /proc/cpuinfo, consider restricting this to logicalNum_dmi > logicalNum && logicalNum_dmi < 1024 (aligned with the later logical update) or otherwise making the comparison direction explicit.

@deepin-ci-robot
Copy link

[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
Copy link
Contributor Author

add-uos commented Jan 22, 2026

/merge

@deepin-bot deepin-bot bot merged commit 42c885d into linuxdeepin:master Jan 22, 2026
18 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