summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Sukhomlinov <sukhomlinov@google.com>2021-09-10 17:19:24 -0700
committerCommit Bot <commit-bot@chromium.org>2021-09-13 19:59:26 +0000
commitbcb5a1c84ae6a3de5eab04d5dd2567291fb2739d (patch)
treeb925966b0e84f28635e00620bc8936ffdfca59cf
parent828bf6cffbfb7d8eafa83a22303dc03c9c48bb01 (diff)
downloadchrome-ec-stabilize-rust-14220.B-cr50_stab.tar.gz
cr50: merge always_memset() and memset()stabilize-rust-14220.B-cr50_stab
There is no point in having separate implementation of always_memset() which is slow and takes few extra bytes. Make memset's body available as memset_core() with volatile dest *, thus making it always called same as with always_memset(). Both memset() and always_memset() becomes just wrappers on top. BUG=none TEST=make BOARD=cr50 CRYPTO_TEST=1; board boots, FIPS tests passes, tpm_test.py works. Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I68b3f89e757521e94df646f7d643411c53a10da7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3155725 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
-rw-r--r--board/cr50/dcrypto/util.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/board/cr50/dcrypto/util.c b/board/cr50/dcrypto/util.c
index 117fec60b4..2529036d4f 100644
--- a/board/cr50/dcrypto/util.c
+++ b/board/cr50/dcrypto/util.c
@@ -80,12 +80,11 @@ __stdlib_compat void *memcpy(void *dest, const void *src, size_t len)
return dest;
}
-
-__stdlib_compat __visible void *memset(void *dest, int c, size_t len)
+static void *memset_core(volatile void *dest, int c, size_t len)
{
- char *d = (char *)dest;
+ volatile char *d = (volatile char *)dest;
uint32_t cccc;
- uint32_t *dw;
+ volatile uint32_t *dw;
char *head;
char * const tail = (char *)dest + len;
/* Set 'body' to the last word boundary */
@@ -106,18 +105,22 @@ __stdlib_compat __visible void *memset(void *dest, int c, size_t len)
*(d++) = c;
/* Copy body */
- dw = (uint32_t *)d;
+ dw = (volatile uint32_t *)d;
while (dw < body)
*(dw++) = cccc;
/* Copy tail */
- d = (char *)dw;
+ d = (volatile char *)dw;
while (d < tail)
*(d++) = c;
- return dest;
+ return (void *)dest;
}
+__stdlib_compat __visible void *memset(void *dest, int c, size_t len)
+{
+ return memset_core(dest, c, len);
+}
__stdlib_compat void *memmove(void *dest, const void *src, size_t len)
{
@@ -204,14 +207,7 @@ __stdlib_compat int strncmp(const char *s1, const char *s2, size_t n)
return 0;
}
-static void always_memset_impl(volatile char *s, int c, size_t n)
-{
- while (n--)
- *s++ = c;
-}
-
void *always_memset(void *s, int c, size_t n)
{
- always_memset_impl(s, c, n);
- return s;
+ return memset_core(s, c, n);
}