diff mbox series

[v1,3/4] virtio-snd: factor card removal out of unrealize()

Message ID 2231ee9229ba7259763c9814e6ec119d8954b81c.1713789200.git.manos.pitsidianakis@linaro.org
State New
Headers show
Series virtio_snd_set_config: Fix #2296 | expand

Commit Message

Manos Pitsidianakis April 22, 2024, 12:52 p.m. UTC
Extract audio card removal logic out of the device unrealize callback so
that it can be re-used in follow up commits.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
 hw/audio/virtio-snd.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

Philippe Mathieu-Daudé April 22, 2024, 1:27 p.m. UTC | #1
On 22/4/24 14:52, Manos Pitsidianakis wrote:
> Extract audio card removal logic out of the device unrealize callback so
> that it can be re-used in follow up commits.
> 
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> ---
>   hw/audio/virtio-snd.c | 20 ++++++++++++++------
>   1 file changed, 14 insertions(+), 6 deletions(-)


> -static void virtio_snd_unrealize(DeviceState *dev)
> +/* Remove audio card and cleanup streams. */
> +static void virtio_snd_unsetup(VirtIOSound *vsnd)

Maybe s/unsetup/cleanup/?

>   {
> -    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> -    VirtIOSound *vsnd = VIRTIO_SND(dev);
>       VirtIOSoundPCMStream *stream;
>   
> -    qemu_del_vm_change_state_handler(vsnd->vmstate);
> -    trace_virtio_snd_unrealize(vsnd);
> -
>       if (vsnd->pcm) {
>           if (vsnd->pcm->streams) {
>               for (uint32_t i = 0; i < vsnd->snd_conf.streams; i++) {
> @@ -1370,6 +1366,18 @@ static void virtio_snd_unrealize(DeviceState *dev)
>           vsnd->pcm = NULL;
>       }
>       AUD_remove_card(&vsnd->card);
> +}
Philippe Mathieu-Daudé April 23, 2024, 8:17 a.m. UTC | #2
On 22/4/24 15:27, Philippe Mathieu-Daudé wrote:
> On 22/4/24 14:52, Manos Pitsidianakis wrote:
>> Extract audio card removal logic out of the device unrealize callback so
>> that it can be re-used in follow up commits.
>>
>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>> ---
>>   hw/audio/virtio-snd.c | 20 ++++++++++++++------
>>   1 file changed, 14 insertions(+), 6 deletions(-)
> 
> 
>> -static void virtio_snd_unrealize(DeviceState *dev)
>> +/* Remove audio card and cleanup streams. */
>> +static void virtio_snd_unsetup(VirtIOSound *vsnd)
> 
> Maybe s/unsetup/cleanup/?

Or 'teardown'?

> 
>>   {
>> -    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>> -    VirtIOSound *vsnd = VIRTIO_SND(dev);
>>       VirtIOSoundPCMStream *stream;
>> -    qemu_del_vm_change_state_handler(vsnd->vmstate);
>> -    trace_virtio_snd_unrealize(vsnd);
>> -
>>       if (vsnd->pcm) {
>>           if (vsnd->pcm->streams) {
>>               for (uint32_t i = 0; i < vsnd->snd_conf.streams; i++) {
>> @@ -1370,6 +1366,18 @@ static void virtio_snd_unrealize(DeviceState *dev)
>>           vsnd->pcm = NULL;
>>       }
>>       AUD_remove_card(&vsnd->card);
>> +}
diff mbox series

Patch

diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index 82dd320ebe..a9cfaea046 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -1343,15 +1343,11 @@  static inline void virtio_snd_pcm_flush(VirtIOSoundPCMStream *stream)
     }
 }
 
-static void virtio_snd_unrealize(DeviceState *dev)
+/* Remove audio card and cleanup streams. */
+static void virtio_snd_unsetup(VirtIOSound *vsnd)
 {
-    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-    VirtIOSound *vsnd = VIRTIO_SND(dev);
     VirtIOSoundPCMStream *stream;
 
-    qemu_del_vm_change_state_handler(vsnd->vmstate);
-    trace_virtio_snd_unrealize(vsnd);
-
     if (vsnd->pcm) {
         if (vsnd->pcm->streams) {
             for (uint32_t i = 0; i < vsnd->snd_conf.streams; i++) {
@@ -1370,6 +1366,18 @@  static void virtio_snd_unrealize(DeviceState *dev)
         vsnd->pcm = NULL;
     }
     AUD_remove_card(&vsnd->card);
+}
+
+static void virtio_snd_unrealize(DeviceState *dev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VirtIOSound *vsnd = VIRTIO_SND(dev);
+
+    qemu_del_vm_change_state_handler(vsnd->vmstate);
+    trace_virtio_snd_unrealize(vsnd);
+
+    virtio_snd_unsetup(vsnd);
+
     qemu_mutex_destroy(&vsnd->cmdq_mutex);
     virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_CONTROL]);
     virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_EVENT]);