[RFC PATCH 09/27] virtio-snd: Add code for set config function

Shreyansh Chouhan posted 27 patches 4 years, 9 months ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
[RFC PATCH 09/27] virtio-snd: Add code for set config function
Posted by Shreyansh Chouhan 4 years, 9 months ago
Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2702@gmail.com>
---
 hw/audio/virtio-snd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index afa38adee7..edaeffd6b7 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -54,6 +54,14 @@ static void virtio_snd_get_config(VirtIODevice *vdev, uint8_t *config)
 
 static void virtio_snd_set_config(VirtIODevice *vdev, const uint8_t *config)
 {
+    VirtIOSound *s = VIRTIO_SOUND(vdev);
+    virtio_snd_config sndcfg;
+
+    memcpy(&sndcfg, config, sizeof(virtio_snd_config));
+
+    memcpy(&s->snd_conf.jacks, &sndcfg.jacks, sizeof(uint32_t));
+    memcpy(&s->snd_conf.streams, &sndcfg.streams, sizeof(uint32_t));
+    memcpy(&s->snd_conf.chmaps, &sndcfg.streams, sizeof(uint32_t));
 }
 
 static const VMStateDescription vmstate_virtio_snd_device = {
-- 
2.25.1


Re: [RFC PATCH 09/27] virtio-snd: Add code for set config function
Posted by Gerd Hoffmann 4 years, 9 months ago
On Thu, Apr 29, 2021 at 05:34:27PM +0530, Shreyansh Chouhan wrote:
> Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2702@gmail.com>
> ---
>  hw/audio/virtio-snd.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
> index afa38adee7..edaeffd6b7 100644
> --- a/hw/audio/virtio-snd.c
> +++ b/hw/audio/virtio-snd.c
> @@ -54,6 +54,14 @@ static void virtio_snd_get_config(VirtIODevice *vdev, uint8_t *config)
>  
>  static void virtio_snd_set_config(VirtIODevice *vdev, const uint8_t *config)
>  {
> +    VirtIOSound *s = VIRTIO_SOUND(vdev);
> +    virtio_snd_config sndcfg;
> +
> +    memcpy(&sndcfg, config, sizeof(virtio_snd_config));
> +
> +    memcpy(&s->snd_conf.jacks, &sndcfg.jacks, sizeof(uint32_t));
> +    memcpy(&s->snd_conf.streams, &sndcfg.streams, sizeof(uint32_t));
> +    memcpy(&s->snd_conf.chmaps, &sndcfg.streams, sizeof(uint32_t));

This is static device information for the driver, the driver should not
be able to change those.  I think you can simply leave the set_config
empty (i.e. just drop this patch).

take care,
  Gerd