summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2017-09-09 02:15:48 +0300
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-09 04:26:49 +0300
commitda436528267ab45fb44ee52a28ebac85b8e24c3d (patch)
treee1d0aa0e8d7e9f580bb98d747bbcaa98394613b8 /lib
parent895a60728f83684e738cce34d7d4e64631505ae4 (diff)
downloadlinux-da436528267ab45fb44ee52a28ebac85b8e24c3d.tar.xz
lib/string.c: check for kmalloc() failure
This is mostly to keep the number of static checker warnings down so we can spot new bugs instead of them being drowned in noise. This function doesn't return normal kernel error codes but instead the return value is used to display exactly which memory failed. I chose -1 as hopefully that's a helpful thing to print. Link: http://lkml.kernel.org/r/20170817115420.uikisjvfmtrqkzjn@mwanda Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Cc: Matthew Wilcox <mawilcox@microsoft.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Kees Cook <keescook@chromium.org> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com> Cc: Daniel Micay <danielmicay@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/string.c b/lib/string.c
index abf6499e3915..9921dc202db4 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1059,7 +1059,11 @@ EXPORT_SYMBOL(fortify_panic);
static __init int memset16_selftest(void)
{
unsigned i, j, k;
- u16 v, *p = kmalloc(256 * 2 * 2, GFP_KERNEL);
+ u16 v, *p;
+
+ p = kmalloc(256 * 2 * 2, GFP_KERNEL);
+ if (!p)
+ return -1;
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
@@ -1091,7 +1095,11 @@ fail:
static __init int memset32_selftest(void)
{
unsigned i, j, k;
- u32 v, *p = kmalloc(256 * 2 * 4, GFP_KERNEL);
+ u32 v, *p;
+
+ p = kmalloc(256 * 2 * 4, GFP_KERNEL);
+ if (!p)
+ return -1;
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
@@ -1123,7 +1131,11 @@ fail:
static __init int memset64_selftest(void)
{
unsigned i, j, k;
- u64 v, *p = kmalloc(256 * 2 * 8, GFP_KERNEL);
+ u64 v, *p;
+
+ p = kmalloc(256 * 2 * 8, GFP_KERNEL);
+ if (!p)
+ return -1;
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {