Don't need indexed button name if only 1 chassis
The commit '31ce375 Support multi power buttons with multi behaviors'
created an assumption that the power button name in gpio_defs.json would
always have a chassis instance number appended to it, and would add an
indexed name as a button factory map key.
That means when ButtonFactor::createInstance() is called with a power
button name without an index, it would not create a PowerButton instance
and button presses wouldn't work.
Instead of changing all of the existing single chassis gpio_defs.json
files in openbmc/openbmc, instead change the factory registration
wrapper code to only register that button as a indexed one if the
provided meson option contains more than 1 chassis.
Tested:
A power button press works to power on the system again.
Fixes: 31ce375e7e71 ("Support multi power buttons with multi behaviors")
Change-Id: I15d02a811aae592adf36c3ac07afd0fc6c15450a
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/inc/button_factory.hpp b/inc/button_factory.hpp
index 26a1831..62b0c72 100644
--- a/inc/button_factory.hpp
+++ b/inc/button_factory.hpp
@@ -2,6 +2,7 @@
#include "button_config.hpp"
#include "button_interface.hpp"
+#include "config.hpp"
#include <phosphor-logging/elog-errors.hpp>
@@ -93,12 +94,21 @@
explicit ButtonIFRegister(size_t count)
{
- // register the class factory function
- // The index, 'countIter', starts at 1 and increments,
- // representing slot_1 through slot_N.
- for (size_t countIter = 1; countIter <= count; countIter++)
+ // The JSON power button definitions only have an instance in
+ // their name if there is more than 1 chassis.
+ if (instances.size() > 1)
{
- ButtonFactory::instance().addToRegistry<T>(countIter);
+ // register the class factory function
+ // The index, 'countIter', starts at 1 and increments,
+ // representing slot_1 through slot_N.
+ for (size_t countIter = 1; countIter <= count; countIter++)
+ {
+ ButtonFactory::instance().addToRegistry<T>(countIter);
+ }
+ }
+ else
+ {
+ ButtonFactory::instance().addToRegistry<T>();
}
}
};