Skip to content

Commit

Permalink
kexec: avoid freeing NULL pointer in image_crash_alloc()
Browse files Browse the repository at this point in the history
Though there is no error if we free a NULL pointer, I think we could
avoid this behaviour.  Change the code a little in kimage_crash_alloc()
could avoid this kind of unnecessary free.

Signed-off-by: Zhang Yanfei <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Sasha Levin <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Zhang Yanfei authored and torvalds committed Feb 28, 2013
1 parent b92e7e0 commit 8c333ac
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions kernel/kexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry,
mend = mstart + image->segment[i].memsz - 1;
/* Ensure we are within the crash kernel limits */
if ((mstart < crashk_res.start) || (mend > crashk_res.end))
goto out;
goto out_free;
}

/*
Expand All @@ -329,16 +329,15 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry,
get_order(KEXEC_CONTROL_PAGE_SIZE));
if (!image->control_code_page) {
printk(KERN_ERR "Could not allocate control_code_buffer\n");
goto out;
goto out_free;
}

result = 0;
out:
if (result == 0)
*rimage = image;
else
kfree(image);
*rimage = image;
return 0;

out_free:
kfree(image);
out:
return result;
}

Expand Down

0 comments on commit 8c333ac

Please sign in to comment.