machine/atsam*, nrf, rp2040, stm32: correct error flashBlockDevice pad() function

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2023-05-05 21:34:35 +02:00
committed by Ron Evans
parent 373ab34492
commit e7363966a5
5 changed files with 16 additions and 16 deletions
+3 -3
View File
@@ -396,12 +396,12 @@ func (f flashBlockDevice) EraseBlocks(start, len int64) error {
// pad data if needed so it is long enough for correct byte alignment on writes.
func (f flashBlockDevice) pad(p []byte) []byte {
paddingNeeded := f.WriteBlockSize() - (int64(len(p)) % f.WriteBlockSize())
if paddingNeeded == 0 {
overflow := int64(len(p)) % f.WriteBlockSize()
if overflow == 0 {
return p
}
padding := bytes.Repeat([]byte{0xff}, int(paddingNeeded))
padding := bytes.Repeat([]byte{0xff}, int(f.WriteBlockSize()-overflow))
return append(p, padding...)
}