]> git.ipfire.org Git - thirdparty/qemu.git/commit - hw/audio/virtio-snd.c
virtio-sound: add realize() error cleanup path
authorManos Pitsidianakis <manos.pitsidianakis@linaro.org>
Thu, 16 Nov 2023 07:20:46 +0000 (09:20 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Sat, 2 Dec 2023 20:56:49 +0000 (15:56 -0500)
commitf7856181849939ecb096dd1d0068b674fe2c69ff
tree6aac24cea989fcef25288aafd4764724989b236c
parent691d3d8bbde16abd002a2590fa422b079d0c8468
virtio-sound: add realize() error cleanup path

QEMU crashes on exit when a virtio-sound device has failed to
realise. Its vmstate field was not cleaned up properly with
qemu_del_vm_change_state_handler().

This patch changes the realize() order as

1. Validate the given configuration values (no resources allocated
   by us either on success or failure)
2. Try AUD_register_card() and return on failure (no resources allocated
   by us on failure)
3. Initialize vmstate, virtio device, heap allocations and stream
   parameters at once.
   If error occurs, goto error_cleanup label which calls
   virtio_snd_unrealize(). This cleans up all resources made in steps
   1-3.

Reported-by: Volker Rümelin <vr_qemu@t-online.de>
Fixes: 2880e676c000 ("Add virtio-sound device stub")
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Message-Id: <20231116072046.4002957-1-manos.pitsidianakis@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
hw/audio/virtio-snd.c