fix(modules/battery): make rate positive if negative

on the Lenovo X13s, the battery firmware returns a negative value for
power_now, which is interpreted by the battery module as 0 because it
converts the string to unsigned long. This should be read as a long
instead, as the kernel specifies that power_now is an int:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/power_supply.h?h=v6.0.11#n99
This commit is contained in:
classabbyamp 2024-03-24 17:16:29 -04:00 committed by Patrick Ziegler
parent 0e5760a824
commit 03d01afed6
1 changed files with 1 additions and 1 deletions

View File

@ -65,7 +65,7 @@ namespace modules {
}
m_rate_reader = make_unique<rate_reader>([this] {
unsigned long rate{std::strtoul(file_util::contents(m_frate).c_str(), nullptr, 10)};
unsigned long rate{static_cast<unsigned long>(std::abs(std::strtol(file_util::contents(m_frate).c_str(), nullptr, 10)))};
unsigned long volt{std::strtoul(file_util::contents(m_fvoltage).c_str(), nullptr, 10) / 1000UL};
unsigned long now{std::strtoul(file_util::contents(m_fcapnow).c_str(), nullptr, 10)};
unsigned long max{std::strtoul(file_util::contents(m_fcapfull).c_str(), nullptr, 10)};