Remove the old dbus interfaces for one i2c bus rescan
During the one bus re-scanning,
the previous found bus interfaces should be removed too.
Tested:
Trigger the one i2c bus re-scan dbus call, no errors,
and ipmitool fru print still works.
Change-Id: If33a34e98fe634d30f1867bf02877ac268797ef4
Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
diff --git a/src/fru_device.cpp b/src/fru_device.cpp
index 60ab7ef..fd083d0 100644
--- a/src/fru_device.cpp
+++ b/src/fru_device.cpp
@@ -979,12 +979,16 @@
sdbusplus::asio::object_server& objServer,
std::shared_ptr<sdbusplus::asio::connection>& systemBus)
{
- for (auto& [pair, interface] : foundDevices)
+ for (auto device = foundDevices.begin(); device != foundDevices.end();)
{
- if (pair.first == static_cast<size_t>(busNum))
+ if (device->first.first == static_cast<size_t>(busNum))
{
- objServer.remove_interface(interface);
- foundDevices.erase(pair);
+ objServer.remove_interface(device->second);
+ device = foundDevices.erase(device);
+ }
+ else
+ {
+ device++;
}
}
@@ -1007,11 +1011,17 @@
i2cBuses, busmap, powerIsOn, objServer,
[busNum, &busmap, &dbusInterfaceMap, &unknownBusObjectCount, &powerIsOn,
&objServer, &systemBus]() {
- for (auto& busIface : dbusInterfaceMap)
+ for (auto busIface = dbusInterfaceMap.begin();
+ busIface != dbusInterfaceMap.end();)
{
- if (busIface.first.first == static_cast<size_t>(busNum))
+ if (busIface->first.first == static_cast<size_t>(busNum))
{
- objServer.remove_interface(busIface.second);
+ objServer.remove_interface(busIface->second);
+ busIface = dbusInterfaceMap.erase(busIface);
+ }
+ else
+ {
+ busIface++;
}
}
auto found = busmap.find(busNum);