memmove_wd: copy chunk down from big address if parameter to is larger than from
When watchdog is enabled, memmove_wd() always copy chunk up from small address. This damanges overlapped memory data if destination address is smaller than source address. Signed-off-by: Sonic Zhang <sonic.zhang@analog.com> Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
eb54d2c70c
commit
22cfddc2a0
|
@ -485,12 +485,22 @@ void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
|
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
|
||||||
|
if (to > from) {
|
||||||
|
from += len;
|
||||||
|
to += len;
|
||||||
|
}
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
size_t tail = (len > chunksz) ? chunksz : len;
|
size_t tail = (len > chunksz) ? chunksz : len;
|
||||||
WATCHDOG_RESET();
|
WATCHDOG_RESET();
|
||||||
|
if (to > from) {
|
||||||
|
to -= tail;
|
||||||
|
from -= tail;
|
||||||
|
}
|
||||||
memmove(to, from, tail);
|
memmove(to, from, tail);
|
||||||
to += tail;
|
if (to < from) {
|
||||||
from += tail;
|
to += tail;
|
||||||
|
from += tail;
|
||||||
|
}
|
||||||
len -= tail;
|
len -= tail;
|
||||||
}
|
}
|
||||||
#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
|
#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
|
||||||
|
|
Loading…
Reference in New Issue