psusensor: don't add fan sensor if not in labels
The checkPWMSensor() function will add a fan sensor to the global array
even if the user has not requested it be added. In this situation, where
the user has not requested this sensor be added for their system, it
will be partially added and appear as a sensor on d-bus. It's only
partially added because code soon after the checkPWMSensor() will check
for the label and notice it's not to be monitored and move on to the
next sensor. But the damage has been done, the fan sensor has been added
to the official dbus sensor list.
This commit duplicates the label check logic a little bit further down
in the code so it's not optimal. But without completely refactoring this
huge function, this seems like the best option.
The current bug is that checkPWMSensor() is called and the sensor is
added to pwmSensors[]. Then once we return from the call, the label
check is done and a continue is issued because the fan sensor is not
in the label list. Because of this, none of the additional code is
run required to initialize the sensor properly.
Tested
- Confirmed the fan sensors are no longer created on IBM System1
Change-Id: If801981295f36cc845e559a76573b488e9c420ac
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/src/psu/PSUSensorMain.cpp b/src/psu/PSUSensorMain.cpp
index d61347b..55888cf 100644
--- a/src/psu/PSUSensorMain.cpp
+++ b/src/psu/PSUSensorMain.cpp
@@ -651,6 +651,22 @@
labelHead.insert(0, "max");
}
+ // Don't add PWM sensors if it's not in label list
+ if (!findLabels.empty())
+ {
+ /* Check if this labelHead is enabled in config file */
+ if (std::find(findLabels.begin(), findLabels.end(),
+ labelHead) == findLabels.end())
+ {
+ if constexpr (debug)
+ {
+ lg2::error(
+ "could not find {LABEL} in the Labels list",
+ "LABEL", labelHead);
+ }
+ continue;
+ }
+ }
checkPWMSensor(sensorPath, labelHead, *interfacePath,
dbusConnection, objectServer, psuNames[0]);
}