diff mbox series

powerpc/sysdev: Use of_device_get_match_data()

Message ID 20220304011830.2061591-1-chi.minghao@zte.com.cn (mailing list archive)
State Changes Requested
Headers show
Series powerpc/sysdev: Use of_device_get_match_data() | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 24 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 7 jobs.

Commit Message

CGEL March 4, 2022, 1:18 a.m. UTC
From: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>

Use of_device_get_match_data() to simplify the code.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
---
 arch/powerpc/sysdev/fsl_msi.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Christophe Leroy March 4, 2022, 1:10 p.m. UTC | #1
Le 04/03/2022 à 02:18, cgel.zte@gmail.com a écrit :
> From: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
> 
> Use of_device_get_match_data() to simplify the code.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
> ---
>   arch/powerpc/sysdev/fsl_msi.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
> index b3475ae9f236..9d135bbb30b7 100644
> --- a/arch/powerpc/sysdev/fsl_msi.c
> +++ b/arch/powerpc/sysdev/fsl_msi.c
> @@ -387,7 +387,6 @@ static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
>   static const struct of_device_id fsl_of_msi_ids[];
>   static int fsl_of_msi_probe(struct platform_device *dev)
>   {
> -	const struct of_device_id *match;
>   	struct fsl_msi *msi;
>   	struct resource res, msiir;
>   	int err, i, j, irq_index, count;
> @@ -397,10 +396,7 @@ static int fsl_of_msi_probe(struct platform_device *dev)
>   	u32 offset;
>   	struct pci_controller *phb;
>   
> -	match = of_match_device(fsl_of_msi_ids, &dev->dev);
> -	if (!match)
> -		return -EINVAL;
> -	features = match->data;
> +	features = of_device_get_match_data(&dev->dev);

What happens when features is NULL ?

>   
>   	printk(KERN_DEBUG "Setting up Freescale MSI support\n");
>
Marc Zyngier March 4, 2022, 2:26 p.m. UTC | #2
On Fri, 04 Mar 2022 13:10:19 +0000,
Christophe Leroy <christophe.leroy@csgroup.eu> wrote:
> 
> 
> 
> Le 04/03/2022 à 02:18, cgel.zte@gmail.com a écrit :
> > From: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
> > 
> > Use of_device_get_match_data() to simplify the code.
> > 
> > Reported-by: Zeal Robot <zealci@zte.com.cn>
> > Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
> > ---
> >   arch/powerpc/sysdev/fsl_msi.c | 6 +-----
> >   1 file changed, 1 insertion(+), 5 deletions(-)
> > 
> > diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
> > index b3475ae9f236..9d135bbb30b7 100644
> > --- a/arch/powerpc/sysdev/fsl_msi.c
> > +++ b/arch/powerpc/sysdev/fsl_msi.c
> > @@ -387,7 +387,6 @@ static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
> >   static const struct of_device_id fsl_of_msi_ids[];
> >   static int fsl_of_msi_probe(struct platform_device *dev)
> >   {
> > -	const struct of_device_id *match;
> >   	struct fsl_msi *msi;
> >   	struct resource res, msiir;
> >   	int err, i, j, irq_index, count;
> > @@ -397,10 +396,7 @@ static int fsl_of_msi_probe(struct platform_device *dev)
> >   	u32 offset;
> >   	struct pci_controller *phb;
> >   
> > -	match = of_match_device(fsl_of_msi_ids, &dev->dev);
> > -	if (!match)
> > -		return -EINVAL;
> > -	features = match->data;
> > +	features = of_device_get_match_data(&dev->dev);
> 
> What happens when features is NULL ?

I did jump at that one too, but as it turns out, it cannot happen, by
construction. All the fsl_of_msi_ids[] entries have a non-NULL .data
pointer, and you only enter probe if you match a fsl_of_msi_ids[]
entry with the DT.

So the current check for a NULL match is not something that can happen
short of some other bug somewhere.

	M.
Christophe Leroy March 4, 2022, 2:29 p.m. UTC | #3
Le 04/03/2022 à 15:26, Marc Zyngier a écrit :
> On Fri, 04 Mar 2022 13:10:19 +0000,
> Christophe Leroy <christophe.leroy@csgroup.eu> wrote:
>>
>>
>>
>> Le 04/03/2022 à 02:18, cgel.zte@gmail.com a écrit :
>>> From: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
>>>
>>> Use of_device_get_match_data() to simplify the code.
>>>
>>> Reported-by: Zeal Robot <zealci@zte.com.cn>
>>> Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
>>> ---
>>>    arch/powerpc/sysdev/fsl_msi.c | 6 +-----
>>>    1 file changed, 1 insertion(+), 5 deletions(-)
>>>
>>> diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
>>> index b3475ae9f236..9d135bbb30b7 100644
>>> --- a/arch/powerpc/sysdev/fsl_msi.c
>>> +++ b/arch/powerpc/sysdev/fsl_msi.c
>>> @@ -387,7 +387,6 @@ static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
>>>    static const struct of_device_id fsl_of_msi_ids[];
>>>    static int fsl_of_msi_probe(struct platform_device *dev)
>>>    {
>>> -	const struct of_device_id *match;
>>>    	struct fsl_msi *msi;
>>>    	struct resource res, msiir;
>>>    	int err, i, j, irq_index, count;
>>> @@ -397,10 +396,7 @@ static int fsl_of_msi_probe(struct platform_device *dev)
>>>    	u32 offset;
>>>    	struct pci_controller *phb;
>>>    
>>> -	match = of_match_device(fsl_of_msi_ids, &dev->dev);
>>> -	if (!match)
>>> -		return -EINVAL;
>>> -	features = match->data;
>>> +	features = of_device_get_match_data(&dev->dev);
>>
>> What happens when features is NULL ?
> 
> I did jump at that one too, but as it turns out, it cannot happen, by
> construction. All the fsl_of_msi_ids[] entries have a non-NULL .data
> pointer, and you only enter probe if you match a fsl_of_msi_ids[]
> entry with the DT.
> 
> So the current check for a NULL match is not something that can happen
> short of some other bug somewhere.
> 

Ok.

Then it would be good to have a sentence explaining that in the commit 
message.

Christophe
Michael Ellerman March 7, 2022, 12:44 a.m. UTC | #4
Christophe Leroy <christophe.leroy@csgroup.eu> writes:
> Le 04/03/2022 à 15:26, Marc Zyngier a écrit :
>> On Fri, 04 Mar 2022 13:10:19 +0000,
>> Christophe Leroy <christophe.leroy@csgroup.eu> wrote:
>>> Le 04/03/2022 à 02:18, cgel.zte@gmail.com a écrit :
>>>> From: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
>>>>
>>>> Use of_device_get_match_data() to simplify the code.
>>>>
>>>> Reported-by: Zeal Robot <zealci@zte.com.cn>
>>>> Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
>>>> ---
>>>>    arch/powerpc/sysdev/fsl_msi.c | 6 +-----
>>>>    1 file changed, 1 insertion(+), 5 deletions(-)
>>>>
>>>> diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
>>>> index b3475ae9f236..9d135bbb30b7 100644
>>>> --- a/arch/powerpc/sysdev/fsl_msi.c
>>>> +++ b/arch/powerpc/sysdev/fsl_msi.c
>>>> @@ -387,7 +387,6 @@ static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
>>>>    static const struct of_device_id fsl_of_msi_ids[];
>>>>    static int fsl_of_msi_probe(struct platform_device *dev)
>>>>    {
>>>> -	const struct of_device_id *match;
>>>>    	struct fsl_msi *msi;
>>>>    	struct resource res, msiir;
>>>>    	int err, i, j, irq_index, count;
>>>> @@ -397,10 +396,7 @@ static int fsl_of_msi_probe(struct platform_device *dev)
>>>>    	u32 offset;
>>>>    	struct pci_controller *phb;
>>>>    
>>>> -	match = of_match_device(fsl_of_msi_ids, &dev->dev);
>>>> -	if (!match)
>>>> -		return -EINVAL;
>>>> -	features = match->data;
>>>> +	features = of_device_get_match_data(&dev->dev);
>>>
>>> What happens when features is NULL ?
>> 
>> I did jump at that one too, but as it turns out, it cannot happen, by
>> construction. All the fsl_of_msi_ids[] entries have a non-NULL .data
>> pointer, and you only enter probe if you match a fsl_of_msi_ids[]
>> entry with the DT.
>> 
>> So the current check for a NULL match is not something that can happen
>> short of some other bug somewhere.
>> 
>
> Ok.
>
> Then it would be good to have a sentence explaining that in the commit 
> message.

Yes I agree. Too many of these cleanup patches assume the reviewer is
intimately familiar with the details of the new API/helper and don't
explain things fully in the change log.

The helper is:

const void *of_device_get_match_data(const struct device *dev)
{
	const struct of_device_id *match;

	match = of_match_device(dev->driver->of_match_table, dev);
	if (!match)
		return NULL;

	return match->data;
}

So as Marc says, if we're in probe then there must be a match.

IMHO there should be a check for match->data being NULL. Although the
current match table contains a non-NULL data for every element, that
could easily change in future (although this driver will probably never
be updated).

The forward declaration of fsl_of_msi_ids should also be removed, as it
will no longer be necessary.

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index b3475ae9f236..9d135bbb30b7 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -387,7 +387,6 @@  static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
 static const struct of_device_id fsl_of_msi_ids[];
 static int fsl_of_msi_probe(struct platform_device *dev)
 {
-	const struct of_device_id *match;
 	struct fsl_msi *msi;
 	struct resource res, msiir;
 	int err, i, j, irq_index, count;
@@ -397,10 +396,7 @@  static int fsl_of_msi_probe(struct platform_device *dev)
 	u32 offset;
 	struct pci_controller *phb;
 
-	match = of_match_device(fsl_of_msi_ids, &dev->dev);
-	if (!match)
-		return -EINVAL;
-	features = match->data;
+	features = of_device_get_match_data(&dev->dev);
 
 	printk(KERN_DEBUG "Setting up Freescale MSI support\n");