Merged
Conversation
usb手写屏接入时,会新增monitor,需要增加对该monitor的处理 Log: 修复usb手写屏热插拔不生效问题 PMS: BUG-276287 Influence: displaylink 显示问题
deepin pr auto reviewGit Diff 代码审查报告总体评价这段代码主要修改了 详细审查意见1. 并发安全问题问题位置: // 问题代码片段
if mm.hooks != nil {
mm.mu.Unlock()
mm.hooks.handleMonitorChanged(monitor)
mm.mu.Lock()
}问题描述:
改进建议: // 改进方案
if mm.hooks != nil {
monitorCopy := *monitor // 创建副本,避免回调修改原始数据
mm.mu.Unlock()
mm.hooks.handleMonitorChanged(&monitorCopy)
mm.mu.Lock()
}2. 错误处理问题问题位置: // 问题代码片段
if monitor == nil || !monitor.Enabled {
logger.Warning("setMonitorFillMode monitor is nil, return.")
return nil
}问题描述:
改进建议: // 改进方案
if monitor == nil {
logger.Warning("setMonitorFillMode monitor is nil, return.")
return fmt.Errorf("monitor is nil")
}
if !monitor.Enabled {
logger.Debug("setMonitorFillMode monitor disabled, skip.")
return nil
}3. 内存安全问题问题位置: // 问题代码片段
if crtcInfo == nil {
continue
}问题描述:
改进建议: // 改进方案
if crtcInfo == nil {
logger.Warningf("crtc %v info is nil", crtc)
continue
}4. 资源管理问题问题位置: // 问题代码片段
if err != nil {
logger.Warningf("get output %v info failed: %v", e.Output, err)
delete(mm.outputs, e.Output)
return
}问题描述:
改进建议: // 改进方案
if err != nil {
logger.Warningf("get output %v info failed: %v", e.Output, err)
// 只在特定错误情况下删除输出,避免误删
if isPermanentError(err) {
delete(mm.outputs, e.Output)
}
return
}5. 代码逻辑问题问题位置: // 问题代码片段
for k, monitor := range oldMonitors {
_, ok := newMap[k]
if !ok {
// 需要移除的monitor
mm.mu.Unlock()
logger.Info("remove monitor:", monitor.ID)
mm.hooks.handleMonitorRemoved(monitor.ID)
mm.mu.Lock()
}
}问题描述:
改进建议: // 改进方案
for k, monitor := range oldMonitors {
_, ok := newMap[k]
if !ok {
// 需要移除的monitor
monitorID := monitor.ID // 保存ID,避免回调修改
if mm.hooks != nil {
mm.mu.Unlock()
logger.Info("remove monitor:", monitorID)
mm.hooks.handleMonitorRemoved(monitorID)
mm.mu.Lock()
}
}
}其他建议
总结这段代码主要改进了显示器管理逻辑,添加了对新增和移除显示器的处理,但存在一些并发安全和错误处理方面的问题。建议重点关注并发安全问题,特别是在持有锁的情况下调用外部回调函数的场景。同时,改进错误处理逻辑,使错误信息更加明确,避免掩盖实际问题。 |
mhduiy
approved these changes
Mar 3, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, mhduiy 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
usb手写屏接入时,会新增monitor,需要增加对该monitor的处理
Log: 修复usb手写屏热插拔不生效问题
PMS: BUG-276287
Influence: displaylink 显示问题