* [PATCH] ASoC: stm32: sai: Use of_device_get_match_data() to simplify code @ 2022-05-19 12:42 Tang Bin 2022-05-23 13:28 ` Olivier MOYSAN 0 siblings, 1 reply; 6+ messages in thread From: Tang Bin @ 2022-05-19 12:42 UTC (permalink / raw) To: olivier.moysan, arnaud.pouliquen, lgirdwood, broonie, perex, tiwai, mcoquelin.stm32, alexandre.torgue Cc: alsa-devel, linux-stm32, linux-arm-kernel, linux-kernel, Tang Bin Retrieve of match data, it's better and cleaner to use 'of_device_get_match_data' over 'of_match_device'. Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> --- sound/soc/stm/stm32_sai_sub.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index dd636af81..d300605a2 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -1500,7 +1500,6 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev, static int stm32_sai_sub_probe(struct platform_device *pdev) { struct stm32_sai_sub_data *sai; - const struct of_device_id *of_id; const struct snd_dmaengine_pcm_config *conf = &stm32_sai_pcm_config; int ret; @@ -1508,10 +1507,9 @@ static int stm32_sai_sub_probe(struct platform_device *pdev) if (!sai) return -ENOMEM; - of_id = of_match_device(stm32_sai_sub_ids, &pdev->dev); - if (!of_id) + sai->id = (uintptr_t)of_device_get_match_data(&pdev->dev); + if (!sai->id) return -EINVAL; - sai->id = (uintptr_t)of_id->data; sai->pdev = pdev; mutex_init(&sai->ctrl_lock); -- 2.20.1.windows.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ASoC: stm32: sai: Use of_device_get_match_data() to simplify code 2022-05-19 12:42 [PATCH] ASoC: stm32: sai: Use of_device_get_match_data() to simplify code Tang Bin @ 2022-05-23 13:28 ` Olivier MOYSAN 2022-05-23 18:57 ` Mark Brown 0 siblings, 1 reply; 6+ messages in thread From: Olivier MOYSAN @ 2022-05-23 13:28 UTC (permalink / raw) To: Tang Bin, arnaud.pouliquen, lgirdwood, broonie, perex, tiwai, mcoquelin.stm32, alexandre.torgue Cc: alsa-devel, linux-stm32, linux-arm-kernel, linux-kernel Hello Tang, Thanks for the patch. Unfortunately this patch introduces a regression. In the SAI driver of_device_id struct the data is a simple enum cast to void* pointer. static const struct of_device_id stm32_sai_sub_ids[] = { .data = (void *)STM_SAI_A_ID}, This data is an ID which can be set to 0x0. Here we have no way to know to discriminate between an error returned by of_device_get_match_data() or a data id set to 0x0. 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}, } Regards Olivier On 5/19/22 14:42, Tang Bin wrote: > Retrieve of match data, it's better and cleaner to use > 'of_device_get_match_data' over 'of_match_device'. > > Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> > --- > sound/soc/stm/stm32_sai_sub.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c > index dd636af81..d300605a2 100644 > --- a/sound/soc/stm/stm32_sai_sub.c > +++ b/sound/soc/stm/stm32_sai_sub.c > @@ -1500,7 +1500,6 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev, > static int stm32_sai_sub_probe(struct platform_device *pdev) > { > struct stm32_sai_sub_data *sai; > - const struct of_device_id *of_id; > const struct snd_dmaengine_pcm_config *conf = &stm32_sai_pcm_config; > int ret; > > @@ -1508,10 +1507,9 @@ static int stm32_sai_sub_probe(struct platform_device *pdev) > if (!sai) > return -ENOMEM; > > - of_id = of_match_device(stm32_sai_sub_ids, &pdev->dev); > - if (!of_id) > + sai->id = (uintptr_t)of_device_get_match_data(&pdev->dev); > + if (!sai->id) > return -EINVAL; > - sai->id = (uintptr_t)of_id->data; > > sai->pdev = pdev; > mutex_init(&sai->ctrl_lock); ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ASoC: stm32: sai: Use of_device_get_match_data() to simplify code 2022-05-23 13:28 ` Olivier MOYSAN @ 2022-05-23 18:57 ` Mark Brown [not found] ` <3fb8d7f8-4506-3b28-22cb-863bda1f21c8@cmss.chinamobile.com> 0 siblings, 1 reply; 6+ messages in thread From: Mark Brown @ 2022-05-23 18:57 UTC (permalink / raw) To: Olivier MOYSAN Cc: Tang Bin, arnaud.pouliquen, lgirdwood, perex, tiwai, mcoquelin.stm32, alexandre.torgue, alsa-devel, linux-stm32, linux-arm-kernel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 487 bytes --] 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). [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <3fb8d7f8-4506-3b28-22cb-863bda1f21c8@cmss.chinamobile.com>]
* Re: [PATCH] ASoC: stm32: sai: Use of_device_get_match_data() tosimplify code [not found] ` <3fb8d7f8-4506-3b28-22cb-863bda1f21c8@cmss.chinamobile.com> @ 2022-05-24 14:30 ` Olivier MOYSAN 2022-05-25 7:36 ` [PATCH] ASoC: stm32: sai: Use of_device_get_match_data()tosimplify code tangbin 0 siblings, 1 reply; 6+ messages in thread From: Olivier MOYSAN @ 2022-05-24 14:30 UTC (permalink / raw) To: tangbin, Mark Brown Cc: arnaud.pouliquen, lgirdwood, perex, tiwai, mcoquelin.stm32, alexandre.torgue, alsa-devel, linux-stm32, linux-arm-kernel, linux-kernel 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. BRs Olivier > Thanks > > Tang Bin > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ASoC: stm32: sai: Use of_device_get_match_data()tosimplify code 2022-05-24 14:30 ` [PATCH] ASoC: stm32: sai: Use of_device_get_match_data() tosimplify code Olivier MOYSAN @ 2022-05-25 7:36 ` tangbin 2022-05-25 12:30 ` Olivier MOYSAN 0 siblings, 1 reply; 6+ messages in thread From: tangbin @ 2022-05-25 7:36 UTC (permalink / raw) To: Olivier MOYSAN, Mark Brown Cc: arnaud.pouliquen, lgirdwood, perex, tiwai, mcoquelin.stm32, alexandre.torgue, alsa-devel, linux-stm32, linux-arm-kernel, linux-kernel 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 >> >> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ASoC: stm32: sai: Use of_device_get_match_data()tosimplify code 2022-05-25 7:36 ` [PATCH] ASoC: stm32: sai: Use of_device_get_match_data()tosimplify code tangbin @ 2022-05-25 12:30 ` Olivier MOYSAN 0 siblings, 0 replies; 6+ messages in thread From: Olivier MOYSAN @ 2022-05-25 12:30 UTC (permalink / raw) To: tangbin, Mark Brown Cc: arnaud.pouliquen, lgirdwood, perex, tiwai, mcoquelin.stm32, alexandre.torgue, alsa-devel, linux-stm32, linux-arm-kernel, linux-kernel Hi Tang, On 5/25/22 09:36, tangbin wrote: > 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. > Yes, these two defines are no more useful. Feel free to send a cleanup patch. BRs Olivier > If you think so, I will send this patch for you. > > > Thanks > > Tang Bin > > >> BRs >> Olivier >> >>> Thanks >>> >>> Tang Bin >>> >>> > > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-05-25 12:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 12:42 [PATCH] ASoC: stm32: sai: Use of_device_get_match_data() to simplify code Tang Bin
2022-05-23 13:28 ` Olivier MOYSAN
2022-05-23 18:57 ` Mark Brown
[not found] ` <3fb8d7f8-4506-3b28-22cb-863bda1f21c8@cmss.chinamobile.com>
2022-05-24 14:30 ` [PATCH] ASoC: stm32: sai: Use of_device_get_match_data() tosimplify code Olivier MOYSAN
2022-05-25 7:36 ` [PATCH] ASoC: stm32: sai: Use of_device_get_match_data()tosimplify code tangbin
2022-05-25 12:30 ` Olivier MOYSAN
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®