* [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
2019-01-09 14:30 ` Michael S. Tsirkin
0 siblings, 2 replies; 4+ 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] 4+ 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
2019-01-09 14:30 ` Michael S. Tsirkin
1 sibling, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2019-01-09 14:30 UTC (permalink / raw)
To: Yi Wang; +Cc: linux-kernel, virtualization, xue.zhihong, huang.zijiang, davem
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] 4+ 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
@ 2019-01-09 14:30 ` Michael S. Tsirkin
2019-01-10 8:13 ` Vincent Stehle
1 sibling, 1 reply; 4+ 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] 4+ messages in thread
* Re: [PATCH] virtio:linux:kernel:NULL check after kmalloc is needed
2019-01-09 14:30 ` Michael S. Tsirkin
@ 2019-01-10 8:13 ` Vincent Stehle
0 siblings, 0 replies; 4+ messages in thread
From: Vincent Stehle @ 2019-01-10 8:13 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Yi Wang, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org, xue.zhihong@zte.com.cn,
huang.zijiang, davem@davemloft.net
Hi,
On Wed, Jan 09, 2019 at 09:30:37AM -0500, Michael S. Tsirkin wrote:
> 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;
> > }
Shouldn't this kzalloc() function return NULL in case of error instead of
-ENOMEM?
Best regards,
Vincent.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-01-10 8:13 UTC | newest]
Thread overview: 4+ 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
2019-01-09 14:30 ` Michael S. Tsirkin
2019-01-10 8:13 ` Vincent Stehle
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.