All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: xgene: Use device_get_match_data() to simplify code
@ 2021-04-01  3:36 Tian Tao
  2021-04-01  9:08 ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Tian Tao @ 2021-04-01  3:36 UTC (permalink / raw)
  To: will, mark.rutland; +Cc: linux-arm-kernel

Use device_get_match_data() here to simplify the code a bit.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/perf/xgene_pmu.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
index ffe3bde..befd2eb 100644
--- a/drivers/perf/xgene_pmu.c
+++ b/drivers/perf/xgene_pmu.c
@@ -1836,7 +1836,6 @@ static int xgene_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
 static int xgene_pmu_probe(struct platform_device *pdev)
 {
 	const struct xgene_pmu_data *dev_data;
-	const struct of_device_id *of_id;
 	struct xgene_pmu *xgene_pmu;
 	struct resource *res;
 	int irq, rc;
@@ -1857,21 +1856,9 @@ static int xgene_pmu_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, xgene_pmu);
 
 	version = -EINVAL;
-	of_id = of_match_device(xgene_pmu_of_match, &pdev->dev);
-	if (of_id) {
-		dev_data = (const struct xgene_pmu_data *) of_id->data;
-		version = dev_data->id;
-	}
-
-#ifdef CONFIG_ACPI
-	if (ACPI_COMPANION(&pdev->dev)) {
-		const struct acpi_device_id *acpi_id;
+	dev_data = device_get_match_data(&pdev->dev);
+	version = dev_data->id;
 
-		acpi_id = acpi_match_device(xgene_pmu_acpi_match, &pdev->dev);
-		if (acpi_id)
-			version = (int) acpi_id->driver_data;
-	}
-#endif
 	if (version < 0)
 		return -ENODEV;
 
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] perf: xgene: Use device_get_match_data() to simplify code
  2021-04-01  3:36 [PATCH] perf: xgene: Use device_get_match_data() to simplify code Tian Tao
@ 2021-04-01  9:08 ` Will Deacon
  2021-04-01  9:17   ` tiantao (H)
  0 siblings, 1 reply; 4+ messages in thread
From: Will Deacon @ 2021-04-01  9:08 UTC (permalink / raw)
  To: Tian Tao; +Cc: mark.rutland, linux-arm-kernel

On Thu, Apr 01, 2021 at 11:36:44AM +0800, Tian Tao wrote:
> Use device_get_match_data() here to simplify the code a bit.
> 
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> ---
>  drivers/perf/xgene_pmu.c | 17 ++---------------
>  1 file changed, 2 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
> index ffe3bde..befd2eb 100644
> --- a/drivers/perf/xgene_pmu.c
> +++ b/drivers/perf/xgene_pmu.c
> @@ -1836,7 +1836,6 @@ static int xgene_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
>  static int xgene_pmu_probe(struct platform_device *pdev)
>  {
>  	const struct xgene_pmu_data *dev_data;
> -	const struct of_device_id *of_id;
>  	struct xgene_pmu *xgene_pmu;
>  	struct resource *res;
>  	int irq, rc;
> @@ -1857,21 +1856,9 @@ static int xgene_pmu_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, xgene_pmu);
>  
>  	version = -EINVAL;
> -	of_id = of_match_device(xgene_pmu_of_match, &pdev->dev);
> -	if (of_id) {
> -		dev_data = (const struct xgene_pmu_data *) of_id->data;
> -		version = dev_data->id;
> -	}
> -
> -#ifdef CONFIG_ACPI
> -	if (ACPI_COMPANION(&pdev->dev)) {
> -		const struct acpi_device_id *acpi_id;
> +	dev_data = device_get_match_data(&pdev->dev);
> +	version = dev_data->id;

What prevents device_get_match_data() from returning NULL? The old code
handled the case where we didn't get a match.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] perf: xgene: Use device_get_match_data() to simplify code
  2021-04-01  9:08 ` Will Deacon
@ 2021-04-01  9:17   ` tiantao (H)
  2021-04-01 17:23     ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: tiantao (H) @ 2021-04-01  9:17 UTC (permalink / raw)
  To: Will Deacon, Tian Tao; +Cc: mark.rutland, linux-arm-kernel


在 2021/4/1 17:08, Will Deacon 写道:
> On Thu, Apr 01, 2021 at 11:36:44AM +0800, Tian Tao wrote:
>> Use device_get_match_data() here to simplify the code a bit.
>>
>> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
>> ---
>>   drivers/perf/xgene_pmu.c | 17 ++---------------
>>   1 file changed, 2 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
>> index ffe3bde..befd2eb 100644
>> --- a/drivers/perf/xgene_pmu.c
>> +++ b/drivers/perf/xgene_pmu.c
>> @@ -1836,7 +1836,6 @@ static int xgene_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
>>   static int xgene_pmu_probe(struct platform_device *pdev)
>>   {
>>   	const struct xgene_pmu_data *dev_data;
>> -	const struct of_device_id *of_id;
>>   	struct xgene_pmu *xgene_pmu;
>>   	struct resource *res;
>>   	int irq, rc;
>> @@ -1857,21 +1856,9 @@ static int xgene_pmu_probe(struct platform_device *pdev)
>>   	platform_set_drvdata(pdev, xgene_pmu);
>>   
>>   	version = -EINVAL;
>> -	of_id = of_match_device(xgene_pmu_of_match, &pdev->dev);
>> -	if (of_id) {
>> -		dev_data = (const struct xgene_pmu_data *) of_id->data;
>> -		version = dev_data->id;
>> -	}
>> -
>> -#ifdef CONFIG_ACPI
>> -	if (ACPI_COMPANION(&pdev->dev)) {
>> -		const struct acpi_device_id *acpi_id;
>> +	dev_data = device_get_match_data(&pdev->dev);
>> +	version = dev_data->id;
> What prevents device_get_match_data() from returning NULL? The old code
> handled the case where we didn't get a match.

What about doing it like this?

diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
index ffe3bde..bd89148 100644
--- a/drivers/perf/xgene_pmu.c
+++ b/drivers/perf/xgene_pmu.c
@@ -1836,7 +1836,6 @@ static int xgene_pmu_offline_cpu(unsigned int cpu, 
struct hlist_node *node)
  static int xgene_pmu_probe(struct platform_device *pdev)
  {
         const struct xgene_pmu_data *dev_data;
-       const struct of_device_id *of_id;
         struct xgene_pmu *xgene_pmu;
         struct resource *res;
         int irq, rc;
@@ -1857,21 +1856,11 @@ static int xgene_pmu_probe(struct 
platform_device *pdev)
         platform_set_drvdata(pdev, xgene_pmu);

         version = -EINVAL;
-       of_id = of_match_device(xgene_pmu_of_match, &pdev->dev);
-       if (of_id) {
-               dev_data = (const struct xgene_pmu_data *) of_id->data;
+       dev_data = device_get_match_data(&pdev->dev);
+       if (dev_data)
                 version = dev_data->id;
-       }
-
-#ifdef CONFIG_ACPI
-       if (ACPI_COMPANION(&pdev->dev)) {
-               const struct acpi_device_id *acpi_id;

-               acpi_id = acpi_match_device(xgene_pmu_acpi_match, 
&pdev->dev);
-               if (acpi_id)
-                       version = (int) acpi_id->driver_data;
-       }
-#endif
         if (version < 0)
                 return -ENODEV;

--
2.7.4

>
> Will
> .
>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] perf: xgene: Use device_get_match_data() to simplify code
  2021-04-01  9:17   ` tiantao (H)
@ 2021-04-01 17:23     ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2021-04-01 17:23 UTC (permalink / raw)
  To: tiantao (H); +Cc: Tian Tao, mark.rutland, linux-arm-kernel

On Thu, Apr 01, 2021 at 05:17:17PM +0800, tiantao (H) wrote:
> 
> 在 2021/4/1 17:08, Will Deacon 写道:
> > On Thu, Apr 01, 2021 at 11:36:44AM +0800, Tian Tao wrote:
> > > Use device_get_match_data() here to simplify the code a bit.
> > > 
> > > Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> > > ---
> > >   drivers/perf/xgene_pmu.c | 17 ++---------------
> > >   1 file changed, 2 insertions(+), 15 deletions(-)
> > > 
> > > diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
> > > index ffe3bde..befd2eb 100644
> > > --- a/drivers/perf/xgene_pmu.c
> > > +++ b/drivers/perf/xgene_pmu.c
> > > @@ -1836,7 +1836,6 @@ static int xgene_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
> > >   static int xgene_pmu_probe(struct platform_device *pdev)
> > >   {
> > >   	const struct xgene_pmu_data *dev_data;
> > > -	const struct of_device_id *of_id;
> > >   	struct xgene_pmu *xgene_pmu;
> > >   	struct resource *res;
> > >   	int irq, rc;
> > > @@ -1857,21 +1856,9 @@ static int xgene_pmu_probe(struct platform_device *pdev)
> > >   	platform_set_drvdata(pdev, xgene_pmu);
> > >   	version = -EINVAL;
> > > -	of_id = of_match_device(xgene_pmu_of_match, &pdev->dev);
> > > -	if (of_id) {
> > > -		dev_data = (const struct xgene_pmu_data *) of_id->data;
> > > -		version = dev_data->id;
> > > -	}
> > > -
> > > -#ifdef CONFIG_ACPI
> > > -	if (ACPI_COMPANION(&pdev->dev)) {
> > > -		const struct acpi_device_id *acpi_id;
> > > +	dev_data = device_get_match_data(&pdev->dev);
> > > +	version = dev_data->id;
> > What prevents device_get_match_data() from returning NULL? The old code
> > handled the case where we didn't get a match.
> 
> What about doing it like this?

Sure, or even just have:

	version = dev_data ? dev_data->id : -EINVAL;

and drop the earlier assignment of -EINVAL;

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-04-01 17:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01  3:36 [PATCH] perf: xgene: Use device_get_match_data() to simplify code Tian Tao
2021-04-01  9:08 ` Will Deacon
2021-04-01  9:17   ` tiantao (H)
2021-04-01 17:23     ` Will Deacon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.