From e7363966a5bc5750616234f0f00476edfa7906e4 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Fri, 5 May 2023 21:34:35 +0200 Subject: [PATCH] machine/atsam*, nrf, rp2040, stm32: correct error flashBlockDevice pad() function Signed-off-by: deadprogram --- src/machine/machine_atsamd21.go | 6 +++--- src/machine/machine_atsamd51.go | 6 +++--- src/machine/machine_nrf.go | 6 +++--- src/machine/machine_rp2040_rom.go | 6 +++--- src/machine/machine_stm32_flash.go | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index 2f4f7338..59df853e 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -1910,12 +1910,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...) } diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index 3c01da41..24ae89aa 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -2239,12 +2239,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...) } diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go index 979693a1..83fa57b3 100644 --- a/src/machine/machine_nrf.go +++ b/src/machine/machine_nrf.go @@ -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...) } diff --git a/src/machine/machine_rp2040_rom.go b/src/machine/machine_rp2040_rom.go index bf93069c..4a8af0f0 100644 --- a/src/machine/machine_rp2040_rom.go +++ b/src/machine/machine_rp2040_rom.go @@ -236,12 +236,12 @@ func (f flashBlockDevice) EraseBlocks(start, length 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...) } diff --git a/src/machine/machine_stm32_flash.go b/src/machine/machine_stm32_flash.go index 898c50dc..710aa05d 100644 --- a/src/machine/machine_stm32_flash.go +++ b/src/machine/machine_stm32_flash.go @@ -92,13 +92,13 @@ 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 } - padded := bytes.Repeat([]byte{0xff}, int(paddingNeeded)) - return append(p, padded...) + padding := bytes.Repeat([]byte{0xff}, int(f.WriteBlockSize()-overflow)) + return append(p, padding...) } const memoryStart = 0x08000000