diff mbox series

vhost: use kzalloc() instead of kmalloc() followed by memset()

Message ID 20230522085019.42914-1-prathubaronia2011@gmail.com (mailing list archive)
State Not Applicable
Headers show
Series vhost: use kzalloc() instead of kmalloc() followed by memset() | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Prathu Baronia May 22, 2023, 8:50 a.m. UTC
Use kzalloc() to allocate new zeroed out msg node instead of
memsetting a node allocated with kmalloc().

Signed-off-by: Prathu Baronia <prathubaronia2011@gmail.com>
---
 drivers/vhost/vhost.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)


base-commit: 4d6d4c7f541d7027beed4fb86eb2c451bd8d6fff

Comments

Stefano Garzarella May 23, 2023, 2:54 p.m. UTC | #1
On Mon, May 22, 2023 at 02:20:19PM +0530, Prathu Baronia wrote:
>Use kzalloc() to allocate new zeroed out msg node instead of
>memsetting a node allocated with kmalloc().
>
>Signed-off-by: Prathu Baronia <prathubaronia2011@gmail.com>
>---
> drivers/vhost/vhost.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
>diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>index a92af08e7864..579ecb4ee4d2 100644
>--- a/drivers/vhost/vhost.c
>+++ b/drivers/vhost/vhost.c
>@@ -2575,12 +2575,11 @@ EXPORT_SYMBOL_GPL(vhost_disable_notify);
> /* Create a new message. */
> struct vhost_msg_node *vhost_new_msg(struct vhost_virtqueue *vq, int type)
> {
>-	struct vhost_msg_node *node = kmalloc(sizeof *node, GFP_KERNEL);
>+	/* Make sure all padding within the structure is initialized. */
>+	struct vhost_msg_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
> 	if (!node)
> 		return NULL;
>
>-	/* Make sure all padding within the structure is initialized. */
>-	memset(&node->msg, 0, sizeof node->msg);

the patch LGTM:

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

> 	node->vq = vq;
> 	node->msg.type = type;
> 	return node;
>
>base-commit: 4d6d4c7f541d7027beed4fb86eb2c451bd8d6fff
>-- 
>2.34.1
>
>
diff mbox series

Patch

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index a92af08e7864..579ecb4ee4d2 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2575,12 +2575,11 @@  EXPORT_SYMBOL_GPL(vhost_disable_notify);
 /* Create a new message. */
 struct vhost_msg_node *vhost_new_msg(struct vhost_virtqueue *vq, int type)
 {
-	struct vhost_msg_node *node = kmalloc(sizeof *node, GFP_KERNEL);
+	/* Make sure all padding within the structure is initialized. */
+	struct vhost_msg_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
 	if (!node)
 		return NULL;
 
-	/* Make sure all padding within the structure is initialized. */
-	memset(&node->msg, 0, sizeof node->msg);
 	node->vq = vq;
 	node->msg.type = type;
 	return node;