aboutsummaryrefslogtreecommitdiffstats
path: root/lib/string.c
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2017-09-08 19:15:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-08 21:26:49 -0400
commitda436528267ab45fb44ee52a28ebac85b8e24c3d (patch)
treee1d0aa0e8d7e9f580bb98d747bbcaa98394613b8 /lib/string.c
parent895a60728f83684e738cce34d7d4e64631505ae4 (diff)
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/string.c')
-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);
1059static __init int memset16_selftest(void) 1059static __init int memset16_selftest(void)
1060{ 1060{
1061 unsigned i, j, k; 1061 unsigned i, j, k;
1062 u16 v, *p = kmalloc(256 * 2 * 2, GFP_KERNEL); 1062 u16 v, *p;
1063
1064 p = kmalloc(256 * 2 * 2, GFP_KERNEL);
1065 if (!p)
1066 return -1;
1063 1067
1064 for (i = 0; i < 256; i++) { 1068 for (i = 0; i < 256; i++) {
1065 for (j = 0; j < 256; j++) { 1069 for (j = 0; j < 256; j++) {
@@ -1091,7 +1095,11 @@ fail:
1091static __init int memset32_selftest(void) 1095static __init int memset32_selftest(void)
1092{ 1096{
1093 unsigned i, j, k; 1097 unsigned i, j, k;
1094 u32 v, *p = kmalloc(256 * 2 * 4, GFP_KERNEL); 1098 u32 v, *p;
1099
1100 p = kmalloc(256 * 2 * 4, GFP_KERNEL);
1101 if (!p)
1102 return -1;
1095 1103
1096 for (i = 0; i < 256; i++) { 1104 for (i = 0; i < 256; i++) {
1097 for (j = 0; j < 256; j++) { 1105 for (j = 0; j < 256; j++) {
@@ -1123,7 +1131,11 @@ fail:
1123static __init int memset64_selftest(void) 1131static __init int memset64_selftest(void)
1124{ 1132{
1125 unsigned i, j, k; 1133 unsigned i, j, k;
1126 u64 v, *p = kmalloc(256 * 2 * 8, GFP_KERNEL); 1134 u64 v, *p;
1135
1136 p = kmalloc(256 * 2 * 8, GFP_KERNEL);
1137 if (!p)
1138 return -1;
1127 1139
1128 for (i = 0; i < 256; i++) { 1140 for (i = 0; i < 256; i++) {
1129 for (j = 0; j < 256; j++) { 1141 for (j = 0; j < 256; j++) {