Re: [PATCH v2 2/5] ALSA: xen-front: Read sound driver configuration from Xen store
From: Juergen Gross
Date: Tue Apr 17 2018 - 07:08:13 EST
On 17/04/18 10:42, Oleksandr Andrushchenko wrote:
> On 04/16/2018 03:55 PM, Juergen Gross wrote:
>> On 16/04/18 08:24, Oleksandr Andrushchenko wrote:
>>> +ÂÂÂÂÂÂÂ goto fail;
>>> +ÂÂÂ }
>>> +
>>> +ÂÂÂ if (!strncasecmp(str, XENSND_STREAM_TYPE_PLAYBACK,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(XENSND_STREAM_TYPE_PLAYBACK))) {
>>> +ÂÂÂÂÂÂÂ stream = &pcm_instance->streams_pb[(*cur_pb)++];
>>> +ÂÂÂ } else if (!strncasecmp(str, XENSND_STREAM_TYPE_CAPTURE,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(XENSND_STREAM_TYPE_CAPTURE))) {
>>> +ÂÂÂÂÂÂÂ stream = &pcm_instance->streams_cap[(*cur_cap)++];
>>> +ÂÂÂ } else {
>>> +ÂÂÂÂÂÂÂ ret = -EINVAL;
>>> +ÂÂÂÂÂÂÂ goto fail;
>>> +ÂÂÂ }
>> Until here this function looks very much like cfg_get_stream_type().
>> Can't they use a common sub-function?
> Not really, because cfg_get_stream_type uses kasprintf
> for strings and this one devm_kasprintf. Trying to make
> a common sub-func doesn't make sense to me
Aah, okay. Didn't spot that.
>>> +ÂÂÂ /* start from default PCM HW configuration for the card */
>>> +ÂÂÂ cfg_read_pcm_hw(xb_dev->nodename, NULL, &cfg->pcm_hw);
>>> +
>>> +ÂÂÂ cfg->pcm_instances =
>>> +ÂÂÂÂÂÂÂÂÂÂÂ devm_kcalloc(&front_info->xb_dev->dev, num_devices,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(struct xen_front_cfg_pcm_instance),
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
>>> +ÂÂÂ if (!cfg->pcm_instances)
>>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>>> +
>>> +ÂÂÂ for (i = 0; i < num_devices; i++) {
>>> +ÂÂÂÂÂÂÂ ret = cfg_device(front_info, &cfg->pcm_instances[i],
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &cfg->pcm_hw, xb_dev->nodename, i, stream_cnt);
>>> +ÂÂÂÂÂÂÂ if (ret < 0)
>>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> Who will free all the memory allocated until now in case of an error?
> The memory is allocated with devm_xxx functions, so it will
> be freed on device destructions automatically
>>
>> And I think when removing the device freeing the memory is missing, too.
> Same as above, the kernel will take care of it while destroying the device
Okay, thanks.
Juergen