[PATCH v5 2/9] ALSA: virtio: add virtio sound driver

Takashi Iwai tiwai at suse.de
Thu Feb 25 11:38:35 CET 2021


On Mon, 22 Feb 2021 16:34:37 +0100,
Anton Yakovlev wrote:
> +static int virtsnd_find_vqs(struct virtio_snd *snd)
> +{
> +	struct virtio_device *vdev = snd->vdev;
> +	vq_callback_t *callbacks[VIRTIO_SND_VQ_MAX] = {
> +		[VIRTIO_SND_VQ_EVENT] = virtsnd_event_notify_cb
> +	};
> +	const char *names[VIRTIO_SND_VQ_MAX] = {

Shouldn't be static?
Also it's often const char * const names[] = { ... }
unless you overwrite something.

> +/**
> + * virtsnd_reset_fn() - Kernel worker's function to reset the device.
> + * @work: Reset device work.
> + *
> + * Context: Process context.
> + */
> +static void virtsnd_reset_fn(struct work_struct *work)
> +{
> +	struct virtio_snd *snd =
> +		container_of(work, struct virtio_snd, reset_work);
> +	struct virtio_device *vdev = snd->vdev;
> +	struct device *dev = &vdev->dev;
> +	int rc;
> +
> +	dev_info(dev, "sound device needs reset\n");
> +
> +	/*
> +	 * It seems that the only way to properly reset the device is to remove
> +	 * and re-create the ALSA sound card device.
> +	 */
> +	rc = device_reprobe(dev);
> +	if (rc)
> +		dev_err(dev, "failed to reprobe sound device: %d\n", rc);

Now I'm wondering whether it's safe to do that from this place.
Basically device_reprobe() unbinds the device that releases the full
resources once including the devm_* stuff.  And this work itself is in
a part of devm allocated resource, so it'll be released there.  That
said, we might hit use-after-free...  This needs to be verified.


thanks,

Takashi


More information about the Alsa-devel mailing list