Fix null pointer dereference in SPD
This commit is contained in:
parent
48f0084a9f
commit
ae94ce1252
4 changed files with 50 additions and 8 deletions
|
|
@ -1124,7 +1124,7 @@ void ResourceManager::DetectDevicesThreadFunction()
|
||||||
LOG_INFO("------------------------------------------------------");
|
LOG_INFO("------------------------------------------------------");
|
||||||
LOG_INFO("| Detecting I2C DIMM modules |");
|
LOG_INFO("| Detecting I2C DIMM modules |");
|
||||||
LOG_INFO("------------------------------------------------------");
|
LOG_INFO("------------------------------------------------------");
|
||||||
for(unsigned int bus = 0; bus < busses.size(); bus++)
|
for(unsigned int bus = 0; bus < busses.size() && IsAnyDimmDetectorEnabled(detector_settings); bus++)
|
||||||
{
|
{
|
||||||
IF_DRAM_SMBUS(busses[bus]->pci_vendor, busses[bus]->pci_device)
|
IF_DRAM_SMBUS(busses[bus]->pci_vendor, busses[bus]->pci_device)
|
||||||
{
|
{
|
||||||
|
|
@ -1175,7 +1175,7 @@ void ResourceManager::DetectDevicesThreadFunction()
|
||||||
/*-------------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Update detection percent |
|
| Update detection percent |
|
||||||
\*-------------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
percent = ((float)i2c_detector_idx + 1.0f) / percent_denominator;
|
percent = (i2c_device_detectors.size() + i2c_detector_idx + 1.0f) / percent_denominator;
|
||||||
|
|
||||||
detection_percent = (unsigned int)(percent * 100.0f);
|
detection_percent = (unsigned int)(percent * 100.0f);
|
||||||
}
|
}
|
||||||
|
|
@ -1223,7 +1223,7 @@ void ResourceManager::DetectDevicesThreadFunction()
|
||||||
/*-------------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Update detection percent |
|
| Update detection percent |
|
||||||
\*-------------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
percent = (i2c_device_detectors.size() + i2c_detector_idx + 1.0f) / percent_denominator;
|
percent = (i2c_device_detectors.size() + i2c_dimm_device_detectors.size() + i2c_detector_idx + 1.0f) / percent_denominator;
|
||||||
|
|
||||||
detection_percent = (unsigned int)(percent * 100.0f);
|
detection_percent = (unsigned int)(percent * 100.0f);
|
||||||
}
|
}
|
||||||
|
|
@ -1378,7 +1378,7 @@ void ResourceManager::DetectDevicesThreadFunction()
|
||||||
\*-------------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
hid_device_count++;
|
hid_device_count++;
|
||||||
|
|
||||||
percent = (i2c_device_detectors.size() + i2c_pci_device_detectors.size() + hid_device_count) / percent_denominator;
|
percent = (i2c_device_detectors.size() + i2c_dimm_device_detectors.size() + i2c_pci_device_detectors.size() + hid_device_count) / percent_denominator;
|
||||||
|
|
||||||
detection_percent = (unsigned int)(percent * 100.0f);
|
detection_percent = (unsigned int)(percent * 100.0f);
|
||||||
|
|
||||||
|
|
@ -1491,7 +1491,7 @@ void ResourceManager::DetectDevicesThreadFunction()
|
||||||
\*-------------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
hid_device_count++;
|
hid_device_count++;
|
||||||
|
|
||||||
percent = (i2c_device_detectors.size() + i2c_pci_device_detectors.size() + hid_device_count) / percent_denominator;
|
percent = (i2c_device_detectors.size() + i2c_dimm_device_detectors.size() + i2c_pci_device_detectors.size() + hid_device_count) / percent_denominator;
|
||||||
|
|
||||||
detection_percent = percent * 100.0f;
|
detection_percent = percent * 100.0f;
|
||||||
|
|
||||||
|
|
@ -1729,6 +1729,21 @@ void ResourceManager::UpdateDetectorSettings()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-------------------------------------------------*\
|
||||||
|
| Loop through all I2C DIMM detectors and see |
|
||||||
|
| if any need to be saved to the settings |
|
||||||
|
\*-------------------------------------------------*/
|
||||||
|
for(unsigned int i2c_detector_idx = 0; i2c_detector_idx < (unsigned int)i2c_dimm_device_detectors.size(); i2c_detector_idx++)
|
||||||
|
{
|
||||||
|
detection_string = i2c_dimm_device_detectors[i2c_detector_idx].name.c_str();
|
||||||
|
|
||||||
|
if(!(detector_settings.contains("detectors") && detector_settings["detectors"].contains(detection_string)))
|
||||||
|
{
|
||||||
|
detector_settings["detectors"][detection_string] = true;
|
||||||
|
save_settings = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Loop through all I2C PCI detectors and see if any |
|
| Loop through all I2C PCI detectors and see if any |
|
||||||
| need to be saved to the settings |
|
| need to be saved to the settings |
|
||||||
|
|
@ -1822,3 +1837,20 @@ void ResourceManager::WaitForDeviceDetection()
|
||||||
DetectDeviceMutex.lock();
|
DetectDeviceMutex.lock();
|
||||||
DetectDeviceMutex.unlock();
|
DetectDeviceMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ResourceManager::IsAnyDimmDetectorEnabled(json &detector_settings)
|
||||||
|
{
|
||||||
|
for(unsigned int i2c_detector_idx = 0; i2c_detector_idx < i2c_dimm_device_detectors.size() && detection_is_required.load(); i2c_detector_idx++)
|
||||||
|
{
|
||||||
|
detection_string = i2c_dimm_device_detectors[i2c_detector_idx].name.c_str();
|
||||||
|
/*-------------------------------------------------*\
|
||||||
|
| Check if this detector is enabled |
|
||||||
|
\*-------------------------------------------------*/
|
||||||
|
if(detector_settings.contains("detectors") && detector_settings["detectors"].contains(detection_string) &&
|
||||||
|
detector_settings["detectors"][detection_string] == false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,9 @@
|
||||||
#include "hidapi_wrapper.h"
|
#include "hidapi_wrapper.h"
|
||||||
#include "i2c_smbus.h"
|
#include "i2c_smbus.h"
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
#define HID_INTERFACE_ANY -1
|
#define HID_INTERFACE_ANY -1
|
||||||
#define HID_USAGE_ANY -1
|
#define HID_USAGE_ANY -1
|
||||||
|
|
@ -231,6 +234,7 @@ private:
|
||||||
void InitThreadFunction();
|
void InitThreadFunction();
|
||||||
bool ProcessPreDetection();
|
bool ProcessPreDetection();
|
||||||
void ProcessPostDetection();
|
void ProcessPostDetection();
|
||||||
|
bool IsAnyDimmDetectorEnabled(json &detector_settings);
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------------------*\
|
||||||
| Static pointer to shared instance of ResourceManager |
|
| Static pointer to shared instance of ResourceManager |
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,10 @@ void SPDDetector::detect_memory_type()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mem_type = (SPDMemoryType) value;
|
mem_type = (SPDMemoryType) value;
|
||||||
valid = true;
|
// We are only interested in DDR4 and DDR5 systems
|
||||||
|
valid = (mem_type == SPD_DDR4_SDRAM || mem_type == SPD_DDR4E_SDRAM ||
|
||||||
|
mem_type == SPD_LPDDR4_SDRAM || mem_type == SPD_LPDDR4X_SDRAM ||
|
||||||
|
mem_type == SPD_DDR5_SDRAM || mem_type == SPD_LPDDR5_SDRAM);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +125,10 @@ i2c_smbus_interface *SPDDetector::smbus() const
|
||||||
|
|
||||||
SPDWrapper::SPDWrapper(const SPDWrapper &wrapper)
|
SPDWrapper::SPDWrapper(const SPDWrapper &wrapper)
|
||||||
{
|
{
|
||||||
this->accessor = wrapper.accessor->copy();
|
if(wrapper.accessor != nullptr)
|
||||||
|
{
|
||||||
|
this->accessor = wrapper.accessor->copy();
|
||||||
|
}
|
||||||
this->address = wrapper.address;
|
this->address = wrapper.address;
|
||||||
this->mem_type = wrapper.mem_type;
|
this->mem_type = wrapper.mem_type;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ class SPDWrapper
|
||||||
uint16_t jedec_id();
|
uint16_t jedec_id();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SPDAccessor *accessor;
|
SPDAccessor *accessor = nullptr;
|
||||||
uint8_t address;
|
uint8_t address;
|
||||||
SPDMemoryType mem_type;
|
SPDMemoryType mem_type;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue