public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio:linux:kernel:NULL check after kmalloc is  needed
@ 2019-01-08  5:40 Yi Wang
  2019-01-09 14:30 ` Michael S. Tsirkin
  0 siblings, 1 reply; 2+ messages in thread
From: Yi Wang @ 2019-01-08  5:40 UTC (permalink / raw)
  To: mst
  Cc: jasowang, davem, virtualization, linux-kernel, xue.zhihong,
	wang.yi59, huang.zijiang

From: "huang.zijiang" <huang.zijiang@zte.com.cn>

NULL check is needed because kmalloc maybe return NULL.

Signed-off-by: huang.zijiang <huang.zijiang@zte.com.cn>
---
 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


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

* Re: [PATCH] virtio:linux:kernel:NULL check after kmalloc is  needed
  2019-01-08  5:40 [PATCH] virtio:linux:kernel:NULL check after kmalloc is needed Yi Wang
@ 2019-01-09 14:30 ` Michael S. Tsirkin
  0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2019-01-09 14:30 UTC (permalink / raw)
  To: Yi Wang
  Cc: jasowang, davem, virtualization, linux-kernel, xue.zhihong,
	huang.zijiang

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

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

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

end of thread, other threads:[~2019-01-09 14:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-08  5:40 [PATCH] virtio:linux:kernel:NULL check after kmalloc is needed Yi Wang
2019-01-09 14:30 ` Michael S. Tsirkin

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