Skip to contentSkip to conversation

cryptodev/vhost: allocate CryptoDevBackendVhost using g_mem0()

PATCH In review Stefano Garzarella 2 participants 2 messages Feb 11, 2025 – Feb 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cryptodev/vhost: allocate CryptoDevBackendVhost using g_mem0()

The function vhost_dev_init() expects the struct vhost_dev (passed as a parameter) to be fully initialized. This is important because some parts of the code check whether vhost_dev->config_ops is NULL to determine if it has been set (e.g. later via vhost_dev_set_config_notifier).

To ensure this initialization, it’s better to allocate the entire CryptoDevBackendVhost structure (which includes vhost_dev) using g_mem0(), following the same approach used for other vhost devices, such as in vhost_net_init().

Fixes 042cea274c ("cryptodev: add vhost-user as a new cryptodev backend")
Reported-by [email protected]
---
 backends/cryptodev-vhost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
backends/cryptodev-vhost.c +1 -1
index 8718c97326..943680a23a 100644
@@ -53,7 +53,7 @@ cryptodev_vhost_init(
     CryptoDevBackendVhost *crypto;
     Error *local_err = NULL;
 
-    crypto = g_new(CryptoDevBackendVhost, 1);
+    crypto = g_new0(CryptoDevBackendVhost, 1);
     crypto->dev.max_queues = 1;
     crypto->dev.nvqs = 1;
     crypto->dev.vqs = crypto->vqs;
Signature · 1 line
2.48.1
Acked-by on v1 1/1
#1 lore raw
Quoted 32 lines · Stefano Garzarella

The function vhost_dev_init() expects the struct vhost_dev (passed as a parameter) to be fully initialized. This is important because some parts of the code check whether vhost_dev->config_ops is NULL to determine if it has been set (e.g. later via vhost_dev_set_config_notifier).

To ensure this initialization, it’s better to allocate the entire CryptoDevBackendVhost structure (which includes vhost_dev) using g_mem0(), following the same approach used for other vhost devices, such as in vhost_net_init().

Fixes 042cea274c ("cryptodev: add vhost-user as a new cryptodev backend")
Reported-by [email protected]
---
  backends/cryptodev-vhost.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
backends/cryptodev-vhost.c +1 -1
index 8718c97326..943680a23a 100644
@@ -53,7 +53,7 @@ cryptodev_vhost_init(
      CryptoDevBackendVhost *crypto;
      Error *local_err = NULL;
 
-    crypto = g_new(CryptoDevBackendVhost, 1);
+    crypto = g_new0(CryptoDevBackendVhost, 1);
      crypto->dev.max_queues = 1;
      crypto->dev.nvqs = 1;
      crypto->dev.vqs = crypto->vqs;