qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PULL 08/63] Add virtio-sound device stub


From: Peter Maydell
Subject: Re: [PULL 08/63] Add virtio-sound device stub
Date: Thu, 9 Nov 2023 14:30:18 +0000

On Tue, 7 Nov 2023 at 10:10, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>
> Add a new VIRTIO device for the virtio sound device id. Functionality
> will be added in the following commits.
>


> +static void virtio_snd_realize(DeviceState *dev, Error **errp)
> +{
> +    ERRP_GUARD();
> +    VirtIOSound *vsnd = VIRTIO_SND(dev);
> +    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> +
> +    vsnd->vmstate =
> +        qemu_add_vm_change_state_handler(virtio_snd_vm_state_change, vsnd);
> +
> +    trace_virtio_snd_realize(vsnd);
> +
> +    virtio_init(vdev, VIRTIO_ID_SOUND, sizeof(virtio_snd_config));
> +    virtio_add_feature(&vsnd->features, VIRTIO_F_VERSION_1);
> +
> +    /* set number of jacks and streams */
> +    if (vsnd->snd_conf.jacks > 8) {
> +        error_setg(errp,
> +                   "Invalid number of jacks: %"PRIu32,
> +                   vsnd->snd_conf.jacks);
> +        return;
> +    }
> +    if (vsnd->snd_conf.streams < 1 || vsnd->snd_conf.streams > 10) {
> +        error_setg(errp,
> +                   "Invalid number of streams: %"PRIu32,
> +                    vsnd->snd_conf.streams);
> +        return;
> +    }
> +
> +    if (vsnd->snd_conf.chmaps > VIRTIO_SND_CHMAP_MAX_SIZE) {
> +        error_setg(errp,
> +                   "Invalid number of channel maps: %"PRIu32,
> +                   vsnd->snd_conf.chmaps);
> +        return;
> +    }
> +
> +    AUD_register_card("virtio-sound", &vsnd->card, errp);

Hi; Coverity points out (CID 1523899) that we don't check the
error from this function. We should check for failure and return
early if so.

> +
> +    vsnd->queues[VIRTIO_SND_VQ_CONTROL] =
> +        virtio_add_queue(vdev, 64, virtio_snd_handle_queue);
> +    vsnd->queues[VIRTIO_SND_VQ_EVENT] =
> +        virtio_add_queue(vdev, 64, virtio_snd_handle_queue);
> +    vsnd->queues[VIRTIO_SND_VQ_TX] =
> +        virtio_add_queue(vdev, 64, virtio_snd_handle_queue);
> +    vsnd->queues[VIRTIO_SND_VQ_RX] =
> +        virtio_add_queue(vdev, 64, virtio_snd_handle_queue);
> +}

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]