Skip to contentSkip to conversation

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

PATCH In review Prathu Baronia 2 participants 2 messages May 22, 2023 – May 23, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

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

Use kzalloc() to allocate new zeroed out msg node instead of memsetting a node allocated with kmalloc().

---
 drivers/vhost/vhost.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/vhost/vhost.c +2 -3
index a92af08e7864..579ecb4ee4d2 100644
@@ -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;

base-commit: 4d6d4c7f541d7027beed4fb86eb2c451bd8d6fff

Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Prathu Baronia

Use kzalloc() to allocate new zeroed out msg node instead of memsetting a node allocated with kmalloc().

---
drivers/vhost/vhost.c | 5 ++---

1 file changed, 2 insertions(+), 3 deletions(-)
drivers/vhost/vhost.c +0 -0
index a92af08e7864..579ecb4ee4d2 100644
@@ -2575,12 +2575,11 @@ EXPORT_SYMBOL_GPL(vhost_disable_notify);
 /* Create a new message. */

drivers/vhost/vhost.c EXPORT_SYMBOL_GPL(vhost_disable_notify); · line 2583

Quoted 10 lines
drivers/vhost/vhost.c +2 -3
 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:

Quoted 9 lines
drivers/vhost/vhost.c +0 -0
 	node->vq = vq;
 	node->msg.type = type;
 	return node;

base-commit: 4d6d4c7f541d7027beed4fb86eb2c451bd8d6fff

Signature · 1 line
2.34.1