lkml.org 
[lkml]   [2021]   [Feb]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v5 2/9] ALSA: virtio: add virtio sound driver
From
Date
On 25.02.2021 11:38, Takashi Iwai wrote:
> 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?

Well, yes. Although in this particular case, I do not think it is that
critical. :)


> Also it's often const char * const names[] = { ... }
> unless you overwrite something.

I tried to use the same type names as in the function prototype.
Otherwise the compiler or static analyzer may complain.


>> +/**
>> + * 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.

It's safe. Suicide kernel workers are funny but possible things. Since
the kernel itself (AFAIU) assumes such a situation and does not access
the worker structure after the callback function call.


> thanks,
>
> Takashi
>

--
Anton Yakovlev
Senior Software Engineer

OpenSynergy GmbH
Rotherstr. 20, 10245 Berlin

\
 
 \ /
  Last update: 2021-02-25 12:54    [W:0.060 / U:0.300 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site