Skip to content

Commit

Permalink
sfdpInternal: Implemented a sanity check for `programmingAndChipErase…
Browse files Browse the repository at this point in the history
…Timing_t::pageSize()`
  • Loading branch information
dragonmux committed Dec 11, 2023
1 parent 9d39068 commit ea46ff6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/include/sfdpInternal.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,15 @@ END_PACKED()
uint8_t programmingTimingRatioAndPageSize{};
std::array<uint8_t, 3> eraseTimings;

[[nodiscard]] uint64_t pageSize() const noexcept
[[nodiscard]] uint32_t pageSize() const noexcept
{
// Extract the exponent, which by definition must be a value between 0 and 15
const auto pageSizeExponent{static_cast<uint8_t>(programmingTimingRatioAndPageSize >> 4U)};
return UINT64_C(1) << pageSizeExponent;
// If for some reason this is 0, return the default page size (256) instead
if (!pageSizeExponent)
return 256U;
// Exponentiate to get the real page size (0-64KiB)
return 1U << pageSizeExponent;
}
};

Expand Down

0 comments on commit ea46ff6

Please sign in to comment.