[PATCH] ASoC: stm32: sai: Use of_device_get_match_data()tosimplify code

tangbin tangbin at cmss.chinamobile.com
Wed May 25 00:36:13 PDT 2022


Hi Olivier:

On 2022/5/24 22:30, Olivier MOYSAN wrote:
> Hi Tang,
>
> On 5/24/22 03:44, tangbin wrote:
>> Hi Mark & Olivier:
>>
>> On 2022/5/24 2:57, Mark Brown wrote:
>>> On Mon, May 23, 2022 at 03:28:48PM +0200, Olivier MOYSAN wrote:
>>>
>>>> The current patch requires a change in the driver.
>>>> Either changing STM_SAI_x_ID enums, or replacing data by a struct.
>>>> For instance:
>>>> struct stm32_sai_comp_data {
>>>>     unsigned int id;
>>>> }
>>>> struct stm32_sai_comp_data stm32_sai_comp_data_a = {
>>>>     .id = STM_SAI_A_ID;
>>>> }
>>>> struct of_device_id stm32_sai_sub_ids[] = {
>>>>     .data = &stm32_sai_comp_data_a},
>>>> }
>>> Either approach works for me (or a revert for that matter).
>>
>>      Thanks for your advice, I was thoughtless.
>>
>>      I think change the date of STM_SAI_x_ID maybe simple. But if we 
>> don't change the id,
>>
>> what about add a "#define" like the line 47:
>>
>> #define STM_SAI_IS_SUB(x) ((x)->id == STM_SAI_A_ID || (x)->id == 
>> STM_SAI_B_ID)
>>
>> then in the judgement, wu use:
>>
>>      sai->id = (uintptr_t)of_device_get_match_data(&pdev->dev);
>>
>>      if (!STM_SAI_IS_SUB(sai))
>>
>>              return -EINVAL;
>>
>>
>> if you think that's ok, I will send patch v2 for you .
>>
>
> If we allow null value in STM_SAI_IS_SUB(sai) check, we can miss real 
> NULL pointer error from of_device_get_match_data().
>
> The simplest way is to change STM_SAI_x_ID enums I think.
> But honnestly, I feel more comfortable to let the driver unchanged.
>
Oh,you are right, I am sorry.

Please forget this patch, I'm sorry to have wasted your time.

But I saw some codes is useless in the line 48 & line 49, I think we can 
remove it.

If you think so, I will send this patch for you.


Thanks

Tang Bin


> BRs
> Olivier
>
>> Thanks
>>
>> Tang Bin
>>
>>





More information about the linux-arm-kernel mailing list