Re: [PATCH RFC] ASoC: simple-card-utils: fix priv->dai_props indexing

From: Laurentiu Mihalcea
Date: Thu Jan 09 2025 - 19:26:22 EST





On 1/9/2025 2:07 AM, Kuninori Morimoto wrote:
> Hi Laurentiu
>
>>>> +#define runtime_simple_priv_to_props(priv, rtd)
>>>> + ((priv)->dai_props + ((rtd)->dai_link - (priv)->dai_link))
>>> Oh yes, indeed.
>>>
>>> But I wonder it is needed not only utils, but all drivers
>>> (= simple-card/audio-graph-card/audio-graph-card2).
>> At this point I'd say there's no need to do the replacement anywhere else. That's because the code
>> still using simple_priv_to_props() makes use of the link number to index the array, which is fine.
>> This is opposed to the PCM runtime data ID that may not correspond to a link number, thus making it
>> unfit for use as an array index.
> Oops, my previous mail indicates strange sample.
>
> I would like to tell was update simple_priv_to_props() itself
>
> - #define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
> + #define simple_priv_to_props(priv, rtd) \
> + ((priv)->dai_props + ((rtd)->dai_link - (priv)->dai_link))
>
> ...
>
> - simple_priv_to_props(priv, rtd->id);
> + simple_priv_to_props(priv, rtd);

ah, thanks for the clarification! correct me if I'm wrong here but the issue
that I see with the suggested approach is that we have some places in which
simple_priv_to_props() is used before the RTD is created.

Example scenario: in audio-graph-card2 we call graph_link_init() (which uses simple_priv_to_props)
before the card is registered (during which the RTD is created).

If the current naming might confuse people then perhaps we could change it to something like

simple_priv_to_props -> simple_props_by_link_idx
runtime_simple_priv_to_props -> simple_props_by_rtd

while also adding some comments on how/when the macros should be used?