Skip to content

Commit 8c333ac

Browse files
Zhang Yanfeitorvalds
authored andcommitted
kexec: avoid freeing NULL pointer in image_crash_alloc()
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]>
1 parent b92e7e0 commit 8c333ac

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

kernel/kexec.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry,
316316
mend = mstart + image->segment[i].memsz - 1;
317317
/* Ensure we are within the crash kernel limits */
318318
if ((mstart < crashk_res.start) || (mend > crashk_res.end))
319-
goto out;
319+
goto out_free;
320320
}
321321

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

335-
result = 0;
336-
out:
337-
if (result == 0)
338-
*rimage = image;
339-
else
340-
kfree(image);
335+
*rimage = image;
336+
return 0;
341337

338+
out_free:
339+
kfree(image);
340+
out:
342341
return result;
343342
}
344343

0 commit comments

Comments
 (0)