frudevice: bail on area_offset == 0
When parsing the fru headers, if the area_offset is 0, just continue.
This reduces the indentation of the interesting code.
Tested: Not tested.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I1868690b2770850733b63a32484e6ac3a439561b
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index b09b8da..72c2a95 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -227,39 +227,41 @@
for (size_t jj = 1; jj <= FRU_AREAS.size(); jj++)
{
auto area_offset = device[jj];
- if (area_offset != 0)
+ if (area_offset == 0)
{
- area_offset = static_cast<char>(area_offset * 8);
- if (read_block_data(flag, file, area_offset, 0x8,
+ continue;
+ }
+
+ area_offset = static_cast<char>(area_offset * 8);
+ if (read_block_data(flag, file, area_offset, 0x8,
+ block_data.data()) < 0)
+ {
+ std::cerr << "failed to read bus " << bus << " address "
+ << ii << "\n";
+ return -1;
+ }
+ int length = block_data[1] * 8;
+ device.insert(device.end(), block_data.begin(),
+ block_data.begin() + 8);
+ length -= 8;
+ area_offset = static_cast<char>(area_offset + 8);
+
+ while (length > 0)
+ {
+ auto to_get = std::min(0x20, length);
+
+ if (read_block_data(flag, file, area_offset,
+ static_cast<uint8_t>(to_get),
block_data.data()) < 0)
{
std::cerr << "failed to read bus " << bus << " address "
<< ii << "\n";
return -1;
}
- int length = block_data[1] * 8;
device.insert(device.end(), block_data.begin(),
- block_data.begin() + 8);
- length -= 8;
- area_offset = static_cast<char>(area_offset + 8);
-
- while (length > 0)
- {
- auto to_get = std::min(0x20, length);
-
- if (read_block_data(flag, file, area_offset,
- static_cast<uint8_t>(to_get),
- block_data.data()) < 0)
- {
- std::cerr << "failed to read bus " << bus
- << " address " << ii << "\n";
- return -1;
- }
- device.insert(device.end(), block_data.begin(),
- block_data.begin() + to_get);
- area_offset = static_cast<char>(area_offset + to_get);
- length -= to_get;
- }
+ block_data.begin() + to_get);
+ area_offset = static_cast<char>(area_offset + to_get);
+ length -= to_get;
}
}
devices->emplace(ii, device);