[PATCH] kexec: check size before trying the malloc
Simon Horman
horms at verge.net.au
Thu Mar 14 04:37:03 EDT 2013
On Thu, Mar 14, 2013 at 01:16:25AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei at 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 at cn.fujitsu.com>
Thanks, applied.
> ---
> 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
>
More information about the kexec
mailing list