qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cryptodev/vhost: allocate CryptoDevBackendVhost using g_mem0()
@ 2025-02-11 13:55 Stefano Garzarella
  2025-02-12  9:28 ` zhenwei pi
  0 siblings, 1 reply; 2+ messages in thread
From: Stefano Garzarella @ 2025-02-11 13:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gonglei (Arei), Zhenwei Pi, Michael S. Tsirkin,
	Stefano Garzarella, qemu-stable, myluo24

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")
Cc: qemu-stable@nongnu.org
Reported-by: myluo24@m.fudan.edu.cn
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 backends/cryptodev-vhost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c
index 8718c97326..943680a23a 100644
--- a/backends/cryptodev-vhost.c
+++ b/backends/cryptodev-vhost.c
@@ -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;
-- 
2.48.1



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

* Re: [PATCH] cryptodev/vhost: allocate CryptoDevBackendVhost using g_mem0()
  2025-02-11 13:55 [PATCH] cryptodev/vhost: allocate CryptoDevBackendVhost using g_mem0() Stefano Garzarella
@ 2025-02-12  9:28 ` zhenwei pi
  0 siblings, 0 replies; 2+ messages in thread
From: zhenwei pi @ 2025-02-12  9:28 UTC (permalink / raw)
  To: Stefano Garzarella, qemu-devel
  Cc: Gonglei (Arei), Michael S. Tsirkin, qemu-stable, myluo24

Acked-by: zhenwei pi <pizhenwei@bytedance.com>

On 2/11/25 21:55, Stefano Garzarella wrote:
> 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")
> Cc: qemu-stable@nongnu.org
> Reported-by: myluo24@m.fudan.edu.cn
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
>   backends/cryptodev-vhost.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c
> index 8718c97326..943680a23a 100644
> --- a/backends/cryptodev-vhost.c
> +++ b/backends/cryptodev-vhost.c
> @@ -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;



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

end of thread, other threads:[~2025-02-12  9:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-11 13:55 [PATCH] cryptodev/vhost: allocate CryptoDevBackendVhost using g_mem0() Stefano Garzarella
2025-02-12  9:28 ` zhenwei pi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).