Skip to content

Commit bec5007

Browse files
nivedita76Ingo Molnar
authored andcommitted
lib/string: Make memzero_explicit() inline instead of external
With the use of the barrier implied by barrier_data(), there is no need for memzero_explicit() to be extern. Making it inline saves the overhead of a function call, and allows the code to be reused in arch/*/purgatory without having to duplicate the implementation. Tested-by: Hans de Goede <[email protected]> Signed-off-by: Arvind Sankar <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: H . Peter Anvin <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephan Mueller <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Fixes: 906a4bb ("crypto: sha256 - Use get/put_unaligned_be32 to get input, memzero_explicit") Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent fbcfb8f commit bec5007

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

include/linux/string.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,26 @@ static inline bool strstarts(const char *str, const char *prefix)
227227
}
228228

229229
size_t memweight(const void *ptr, size_t bytes);
230-
void memzero_explicit(void *s, size_t count);
230+
231+
/**
232+
* memzero_explicit - Fill a region of memory (e.g. sensitive
233+
* keying data) with 0s.
234+
* @s: Pointer to the start of the area.
235+
* @count: The size of the area.
236+
*
237+
* Note: usually using memset() is just fine (!), but in cases
238+
* where clearing out _local_ data at the end of a scope is
239+
* necessary, memzero_explicit() should be used instead in
240+
* order to prevent the compiler from optimising away zeroing.
241+
*
242+
* memzero_explicit() doesn't need an arch-specific version as
243+
* it just invokes the one of memset() implicitly.
244+
*/
245+
static inline void memzero_explicit(void *s, size_t count)
246+
{
247+
memset(s, 0, count);
248+
barrier_data(s);
249+
}
231250

232251
/**
233252
* kbasename - return the last part of a pathname.

lib/string.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -748,27 +748,6 @@ void *memset(void *s, int c, size_t count)
748748
EXPORT_SYMBOL(memset);
749749
#endif
750750

751-
/**
752-
* memzero_explicit - Fill a region of memory (e.g. sensitive
753-
* keying data) with 0s.
754-
* @s: Pointer to the start of the area.
755-
* @count: The size of the area.
756-
*
757-
* Note: usually using memset() is just fine (!), but in cases
758-
* where clearing out _local_ data at the end of a scope is
759-
* necessary, memzero_explicit() should be used instead in
760-
* order to prevent the compiler from optimising away zeroing.
761-
*
762-
* memzero_explicit() doesn't need an arch-specific version as
763-
* it just invokes the one of memset() implicitly.
764-
*/
765-
void memzero_explicit(void *s, size_t count)
766-
{
767-
memset(s, 0, count);
768-
barrier_data(s);
769-
}
770-
EXPORT_SYMBOL(memzero_explicit);
771-
772751
#ifndef __HAVE_ARCH_MEMSET16
773752
/**
774753
* memset16() - Fill a memory area with a uint16_t

0 commit comments

Comments
 (0)