linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] spi: davinci: Use of_device_get_match_data() helper
@ 2021-03-30 12:31 Tian Tao
  2021-03-30 12:36 ` Fabio Estevam
  0 siblings, 1 reply; 6+ messages in thread
From: Tian Tao @ 2021-03-30 12:31 UTC (permalink / raw)
  To: broonie, festevam; +Cc: linux-spi

Use the of_device_get_match_data() helper instead of open coding.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
v2: Removed forced type conversions
---
 drivers/spi/spi-davinci.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 7453a1d..9122235 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -817,19 +817,16 @@ static int spi_davinci_get_pdata(struct platform_device *pdev,
 			struct davinci_spi *dspi)
 {
 	struct device_node *node = pdev->dev.of_node;
-	struct davinci_spi_of_data *spi_data;
+	const struct davinci_spi_of_data *spi_data;
 	struct davinci_spi_platform_data *pdata;
 	unsigned int num_cs, intr_line = 0;
-	const struct of_device_id *match;
 
 	pdata = &dspi->pdata;
 
-	match = of_match_device(davinci_spi_of_match, &pdev->dev);
-	if (!match)
+	spi_data = of_device_get_match_data(&pdev->dev);
+	if (!spi_data)
 		return -ENODEV;
 
-	spi_data = (struct davinci_spi_of_data *)match->data;
-
 	pdata->version = spi_data->version;
 	pdata->prescaler_limit = spi_data->prescaler_limit;
 	/*
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] spi: davinci: Use of_device_get_match_data() helper
  2021-03-30 12:31 [PATCH v2] spi: davinci: Use of_device_get_match_data() helper Tian Tao
@ 2021-03-30 12:36 ` Fabio Estevam
  2021-03-30 12:47   ` tiantao (H)
  0 siblings, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2021-03-30 12:36 UTC (permalink / raw)
  To: Tian Tao; +Cc: Mark Brown, linux-spi

On Tue, Mar 30, 2021 at 9:30 AM Tian Tao <tiantao6@hisilicon.com> wrote:

> -       match = of_match_device(davinci_spi_of_match, &pdev->dev);
> -       if (!match)
> +       spi_data = of_device_get_match_data(&pdev->dev);
> +       if (!spi_data)

No need to check against NULL here because all compatible strings
provide .data and DT is the only mechanism to probe.

Also, this could be device_get_match_data().

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] spi: davinci: Use of_device_get_match_data() helper
  2021-03-30 12:36 ` Fabio Estevam
@ 2021-03-30 12:47   ` tiantao (H)
  2021-03-30 12:49     ` Fabio Estevam
  0 siblings, 1 reply; 6+ messages in thread
From: tiantao (H) @ 2021-03-30 12:47 UTC (permalink / raw)
  To: Fabio Estevam, Tian Tao; +Cc: Mark Brown, linux-spi


在 2021/3/30 20:36, Fabio Estevam 写道:
> On Tue, Mar 30, 2021 at 9:30 AM Tian Tao <tiantao6@hisilicon.com> wrote:
>
>> -       match = of_match_device(davinci_spi_of_match, &pdev->dev);
>> -       if (!match)
>> +       spi_data = of_device_get_match_data(&pdev->dev);
>> +       if (!spi_data)
> No need to check against NULL here because all compatible strings
> provide .data and DT is the only mechanism to probe.
>
> Also, this could be device_get_match_data().
> .

What about doing it like this?

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c

index 7453a1d..e114e6fe 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -817,18 +817,13 @@ static int spi_davinci_get_pdata(struct 
platform_device *pdev,
                         struct davinci_spi *dspi)
  {
         struct device_node *node = pdev->dev.of_node;
-       struct davinci_spi_of_data *spi_data;
+       const struct davinci_spi_of_data *spi_data;
         struct davinci_spi_platform_data *pdata;
         unsigned int num_cs, intr_line = 0;
-       const struct of_device_id *match;

         pdata = &dspi->pdata;

-       match = of_match_device(davinci_spi_of_match, &pdev->dev);
-       if (!match)
-               return -ENODEV;
-
-       spi_data = (struct davinci_spi_of_data *)match->data;
+       spi_data = device_get_match_data(&pdev->dev);

         pdata->version = spi_data->version;
         pdata->prescaler_limit = spi_data->prescaler_limit;



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] spi: davinci: Use of_device_get_match_data() helper
  2021-03-30 12:47   ` tiantao (H)
@ 2021-03-30 12:49     ` Fabio Estevam
  2021-03-30 12:53       ` tiantao (H)
  0 siblings, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2021-03-30 12:49 UTC (permalink / raw)
  To: tiantao (H); +Cc: Tian Tao, Mark Brown, linux-spi

On Tue, Mar 30, 2021 at 9:48 AM tiantao (H) <tiantao6@huawei.com> wrote:

> What about doing it like this?

Yes, this is what I suggested before :-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] spi: davinci: Use of_device_get_match_data() helper
  2021-03-30 12:49     ` Fabio Estevam
@ 2021-03-30 12:53       ` tiantao (H)
  2021-03-30 12:55         ` Fabio Estevam
  0 siblings, 1 reply; 6+ messages in thread
From: tiantao (H) @ 2021-03-30 12:53 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: Tian Tao, Mark Brown, linux-spi


在 2021/3/30 20:49, Fabio Estevam 写道:
> On Tue, Mar 30, 2021 at 9:48 AM tiantao (H) <tiantao6@huawei.com> wrote:
>
>> What about doing it like this?
> Yes, this is what I suggested before :-)
> .

thank you,I will send a new patch for this.

can I add Signed-off-by: Fabio Estevam <festevam@gmail.com>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] spi: davinci: Use of_device_get_match_data() helper
  2021-03-30 12:53       ` tiantao (H)
@ 2021-03-30 12:55         ` Fabio Estevam
  0 siblings, 0 replies; 6+ messages in thread
From: Fabio Estevam @ 2021-03-30 12:55 UTC (permalink / raw)
  To: tiantao (H); +Cc: Tian Tao, Mark Brown, linux-spi

On Tue, Mar 30, 2021 at 9:53 AM tiantao (H) <tiantao6@huawei.com> wrote:

> thank you,I will send a new patch for this.
>
> can I add Signed-off-by: Fabio Estevam <festevam@gmail.com>

Please add:

Suggested-by: Fabio Estevam <festevam@gmail.com>

Also, in v3 don't forget to change the Subject from
of_device_get_match_data() to device_get_match_data().

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-30 12:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 12:31 [PATCH v2] spi: davinci: Use of_device_get_match_data() helper Tian Tao
2021-03-30 12:36 ` Fabio Estevam
2021-03-30 12:47   ` tiantao (H)
2021-03-30 12:49     ` Fabio Estevam
2021-03-30 12:53       ` tiantao (H)
2021-03-30 12:55         ` Fabio Estevam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).