Re: [PATCH v2 4/5] ALSA: xen-front: Implement handling of shared buffers

From: Juergen Gross
Date: Tue Apr 17 2018 - 07:16:00 EST


On 17/04/18 11:22, Oleksandr Andrushchenko wrote:
> On 04/16/2018 04:39 PM, Juergen Gross wrote:
>> On 16/04/18 08:24, Oleksandr Andrushchenko wrote:
>>> +static int alloc_int_buffers(struct xen_snd_front_shbuf *buf,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int num_pages_dir, int num_pages_buffer,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int num_grefs)
>>> +{
>>> +ÂÂÂ buf->grefs = kcalloc(num_grefs, sizeof(*buf->grefs), GFP_KERNEL);
>>> +ÂÂÂ if (!buf->grefs)
>>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>>> +
>>> +ÂÂÂ buf->directory = kcalloc(num_pages_dir, XEN_PAGE_SIZE, GFP_KERNEL);
>>> +ÂÂÂ if (!buf->directory)
>>> +ÂÂÂÂÂÂÂ goto fail;
>>> +
>>> +ÂÂÂ buf->buffer_sz = num_pages_buffer * XEN_PAGE_SIZE;
>>> +ÂÂÂ buf->buffer = alloc_pages_exact(buf->buffer_sz, GFP_KERNEL);
>>> +ÂÂÂ if (!buf->buffer)
>>> +ÂÂÂÂÂÂÂ goto fail;
>>> +
>>> +ÂÂÂ return 0;
>>> +
>>> +fail:
>>> +ÂÂÂ kfree(buf->grefs);
>>> +ÂÂÂ buf->grefs = NULL;
>>> +ÂÂÂ kfree(buf->directory);
>> Why do you need to free those here? Shouldn't that be done via
>> xen_snd_front_shbuf_free() in case of an error?
> At this place we only allocate memory, but xen_snd_front_shbuf_free
> will also try to gnttab_end_foreign_access if buf->grefs != NULL.

Okay.


Juergen