linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: davinci: Use of_device_get_match_data() helper
@ 2021-03-29  8:58 Tian Tao
  2021-03-29 15:21 ` Mark Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Tian Tao @ 2021-03-29  8:58 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi

Use the of_device_get_match_data() helper instead of open coding.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/spi/spi-davinci.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 7453a1d..869045f 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -820,16 +820,14 @@ static int spi_davinci_get_pdata(struct platform_device *pdev,
 	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 = (struct davinci_spi_of_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] 9+ messages in thread

* Re: [PATCH] spi: davinci: Use of_device_get_match_data() helper
  2021-03-29  8:58 [PATCH] spi: davinci: Use of_device_get_match_data() helper Tian Tao
@ 2021-03-29 15:21 ` Mark Brown
  2021-03-30  0:53   ` tiantao (H)
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2021-03-29 15:21 UTC (permalink / raw)
  To: Tian Tao; +Cc: linux-spi

[-- Attachment #1: Type: text/plain, Size: 243 bytes --]

On Mon, Mar 29, 2021 at 04:58:36PM +0800, Tian Tao wrote:

> +	spi_data = (struct davinci_spi_of_data *)
> +			of_device_get_match_data(&pdev->dev);
> +	if (!spi_data)

If we need to cast away from void * that's most likely pointing at a
bug.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] spi: davinci: Use of_device_get_match_data() helper
  2021-03-29 15:21 ` Mark Brown
@ 2021-03-30  0:53   ` tiantao (H)
  2021-03-30 10:47     ` Mark Brown
  2021-03-30 11:56     ` Fabio Estevam
  0 siblings, 2 replies; 9+ messages in thread
From: tiantao (H) @ 2021-03-30  0:53 UTC (permalink / raw)
  To: Mark Brown, Tian Tao; +Cc: linux-spi


在 2021/3/29 23:21, Mark Brown 写道:
> On Mon, Mar 29, 2021 at 04:58:36PM +0800, Tian Tao wrote:
>
>> +	spi_data = (struct davinci_spi_of_data *)
>> +			of_device_get_match_data(&pdev->dev);
>> +	if (!spi_data)
> If we need to cast away from void * that's most likely pointing at a
> bug.

Even with of_match_device, there is still a type conversion,as follows

spi_data = (struct davinci_spi_of_data *)match->data;

Using of_device_get_match_data instead of of_match_device doesn't look 
like a problem from the code, other spi drivers do the same thing



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

* Re: [PATCH] spi: davinci: Use of_device_get_match_data() helper
  2021-03-30  0:53   ` tiantao (H)
@ 2021-03-30 10:47     ` Mark Brown
  2021-03-30 11:56     ` Fabio Estevam
  1 sibling, 0 replies; 9+ messages in thread
From: Mark Brown @ 2021-03-30 10:47 UTC (permalink / raw)
  To: tiantao (H); +Cc: Tian Tao, linux-spi

[-- Attachment #1: Type: text/plain, Size: 580 bytes --]

On Tue, Mar 30, 2021 at 08:53:00AM +0800, tiantao (H) wrote:
> 在 2021/3/29 23:21, Mark Brown 写道:
> > On Mon, Mar 29, 2021 at 04:58:36PM +0800, Tian Tao wrote:

> > > +	spi_data = (struct davinci_spi_of_data *)
> > > +			of_device_get_match_data(&pdev->dev);
> > > +	if (!spi_data)

> > If we need to cast away from void * that's most likely pointing at a
> > bug.

> Even with of_match_device, there is still a type conversion,as follows

> spi_data = (struct davinci_spi_of_data *)match->data;

A type conversion which shouldn't have any need for a cast.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] spi: davinci: Use of_device_get_match_data() helper
  2021-03-30  0:53   ` tiantao (H)
  2021-03-30 10:47     ` Mark Brown
@ 2021-03-30 11:56     ` Fabio Estevam
  2021-03-30 12:11       ` tiantao (H)
  2021-03-30 12:12       ` Mark Brown
  1 sibling, 2 replies; 9+ messages in thread
From: Fabio Estevam @ 2021-03-30 11:56 UTC (permalink / raw)
  To: tiantao (H); +Cc: Mark Brown, Tian Tao, linux-spi

On Mon, Mar 29, 2021 at 9:54 PM tiantao (H) <tiantao6@huawei.com> wrote:

> Even with of_match_device, there is still a type conversion,as follows
>
> spi_data = (struct davinci_spi_of_data *)match->data;
>
> Using of_device_get_match_data instead of of_match_device doesn't look
> like a problem from the code, other spi drivers do the same thing

What about doing it like this?

--- 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	[flat|nested] 9+ messages in thread

* Re: [PATCH] spi: davinci: Use of_device_get_match_data() helper
  2021-03-30 11:56     ` Fabio Estevam
@ 2021-03-30 12:11       ` tiantao (H)
  2021-03-30 12:15         ` Fabio Estevam
  2021-03-30 12:12       ` Mark Brown
  1 sibling, 1 reply; 9+ messages in thread
From: tiantao (H) @ 2021-03-30 12:11 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: Mark Brown, Tian Tao, linux-spi


在 2021/3/30 19:56, Fabio Estevam 写道:
> On Mon, Mar 29, 2021 at 9:54 PM tiantao (H) <tiantao6@huawei.com> wrote:
>
>> Even with of_match_device, there is still a type conversion,as follows
>>
>> spi_data = (struct davinci_spi_of_data *)match->data;
>>
>> Using of_device_get_match_data instead of of_match_device doesn't look
>> like a problem from the code, other spi drivers do the same thing
> What about doing it like this?
thanks.

 From what I have tested, the results are ok. I will send v2 to fix.

make modules M=drivers/spi/
   CC [M]  drivers/spi//spi-davinci.o
drivers/spi//spi-davinci.c: In function ‘spi_davinci_get_pdata’:
drivers/spi//spi-davinci.c:826:11: warning: assignment discards ‘const’ 
qualifier from pointer target type [-Wdiscarded-qualifiers]
   826 |  spi_data = of_device_get_match_data(&pdev->dev);
       |           ^
   MODPOST drivers/spi//Module.symvers

   LD [M]  drivers/spi//spi-davinci.ko

  vim drivers/spi//spi-davinci.c
make modules M=drivers/spi/
   CC [M]  drivers/spi//spi-davinci.o
   MODPOST drivers/spi//Module.symvers
   LD [M]  drivers/spi//spi-davinci.ko
>
> --- 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	[flat|nested] 9+ messages in thread

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

[-- Attachment #1: Type: text/plain, Size: 233 bytes --]

On Tue, Mar 30, 2021 at 08:56:41AM -0300, Fabio Estevam wrote:

> What about doing it like this?

> -       spi_data = (struct davinci_spi_of_data *)match->data;
> +       spi_data = device_get_match_data(&pdev->dev);

Yes, exactly.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

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

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

>  From what I have tested, the results are ok. I will send v2 to fix.
>
> make modules M=drivers/spi/
>    CC [M]  drivers/spi//spi-davinci.o
> drivers/spi//spi-davinci.c: In function ‘spi_davinci_get_pdata’:
> drivers/spi//spi-davinci.c:826:11: warning: assignment discards ‘const’
> qualifier from pointer target type [-Wdiscarded-qualifiers]
>    826 |  spi_data = of_device_get_match_data(&pdev->dev);

This warning does not appear if you apply the patch I suggested.

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

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


在 2021/3/30 20:15, Fabio Estevam 写道:
> On Tue, Mar 30, 2021 at 9:12 AM tiantao (H) <tiantao6@huawei.com> wrote:
>
>>   From what I have tested, the results are ok. I will send v2 to fix.
>>
>> make modules M=drivers/spi/
>>     CC [M]  drivers/spi//spi-davinci.o
>> drivers/spi//spi-davinci.c: In function ‘spi_davinci_get_pdata’:
>> drivers/spi//spi-davinci.c:826:11: warning: assignment discards ‘const’
>> qualifier from pointer target type [-Wdiscarded-qualifiers]
>>     826 |  spi_data = of_device_get_match_data(&pdev->dev);
Yes, I added the const as you suggested and there is no more warning
> This warning does not appear if you apply the patch I suggested.
> .
>


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

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

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29  8:58 [PATCH] spi: davinci: Use of_device_get_match_data() helper Tian Tao
2021-03-29 15:21 ` Mark Brown
2021-03-30  0:53   ` tiantao (H)
2021-03-30 10:47     ` Mark Brown
2021-03-30 11:56     ` Fabio Estevam
2021-03-30 12:11       ` tiantao (H)
2021-03-30 12:15         ` Fabio Estevam
2021-03-30 12:17           ` tiantao (H)
2021-03-30 12:12       ` Mark Brown

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).