public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] kexec: check size before trying the malloc
@ 2013-03-13 17:16 Zhang Yanfei
  2013-03-14  8:37 ` Simon Horman
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:16 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

If size is zero, it is unnecessary to do the malloc operation.
So checking size first is better than doing malloc first.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/kexec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index 3ef6f0d..494c5b3 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -76,9 +76,9 @@ static char *xstrdup(const char *str)
 void *xmalloc(size_t size)
 {
 	void *buf;
-	buf = malloc(size);
 	if (!size)
 		return NULL;
+	buf = malloc(size);
 	if (!buf) {
 		die("Cannot malloc %ld bytes: %s\n",
 			size + 0UL, strerror(errno));
-- 
1.7.1

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-03-14 10:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-13 17:16 [PATCH] kexec: check size before trying the malloc Zhang Yanfei
2013-03-14  8:37 ` Simon Horman
2013-03-14 10:26   ` HATAYAMA Daisuke
2013-03-14 10:30     ` HATAYAMA Daisuke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox