Skip to content

Commit

Permalink
lib/string.c: check for kmalloc() failure
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Stephen Rothwell <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Daniel Micay <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Dan Carpenter authored and torvalds committed Sep 9, 2017
1 parent 895a607 commit da43652
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -1091,7 +1095,11 @@ static __init int memset16_selftest(void)
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++) {
Expand Down Expand Up @@ -1123,7 +1131,11 @@ static __init int memset32_selftest(void)
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++) {
Expand Down

0 comments on commit da43652

Please sign in to comment.