2019-01-08 05:50:56

by Yi Wang

[permalink] [raw]
Subject: [PATCH] virtio:linux:kernel:NULL check after kmalloc is needed

From: "huang.zijiang" <[email protected]>

NULL check is needed because kmalloc maybe return NULL.

Signed-off-by: huang.zijiang <[email protected]>
---
tools/virtio/linux/kernel.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h
index 7ef45a4..2afcad8 100644
--- a/tools/virtio/linux/kernel.h
+++ b/tools/virtio/linux/kernel.h
@@ -65,6 +65,8 @@ static inline void *kzalloc(size_t s, gfp_t gfp)
{
void *p = kmalloc(s, gfp);

+ if (!p)
+ return -ENOMEM;
memset(p, 0, s);
return p;
}
--
1.8.3.1



2019-01-09 14:37:33

by Michael S. Tsirkin

[permalink] [raw]
Subject: Re: [PATCH] virtio:linux:kernel:NULL check after kmalloc is needed

On Tue, Jan 08, 2019 at 01:40:33PM +0800, Yi Wang wrote:
> From: "huang.zijiang" <[email protected]>
>
> NULL check is needed because kmalloc maybe return NULL.
>
> Signed-off-by: huang.zijiang <[email protected]>

Can't hurt I will queue it.

> ---
> tools/virtio/linux/kernel.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h
> index 7ef45a4..2afcad8 100644
> --- a/tools/virtio/linux/kernel.h
> +++ b/tools/virtio/linux/kernel.h
> @@ -65,6 +65,8 @@ static inline void *kzalloc(size_t s, gfp_t gfp)
> {
> void *p = kmalloc(s, gfp);
>
> + if (!p)
> + return -ENOMEM;
> memset(p, 0, s);
> return p;
> }
> --
> 1.8.3.1