[PATCH v2] perf: xgene: Use device_get_match_data() to simplify code

Will Deacon will at kernel.org
Wed Apr 7 13:18:56 BST 2021


On Fri, Apr 02, 2021 at 09:10:38AM +0800, Tian Tao wrote:
> Use device_get_match_data() here to simplify the code a bit.
> 
> Signed-off-by: Tian Tao <tiantao6 at hisilicon.com>
> ---
> v2:handled the case which device_get_match_data() return NULL.
> ---
>  drivers/perf/xgene_pmu.c | 18 ++----------------
>  1 file changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
> index ffe3bde..45f36c1 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;
> @@ -1856,22 +1855,9 @@ static int xgene_pmu_probe(struct platform_device *pdev)
>  	xgene_pmu->dev = &pdev->dev;
>  	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);
>  
> -		acpi_id = acpi_match_device(xgene_pmu_acpi_match, &pdev->dev);
> -		if (acpi_id)
> -			version = (int) acpi_id->driver_data;
> -	}
> -#endif
> +	version = dev_data ? dev_data->id : -EINVAL;
>  	if (version < 0)
>  		return -ENODEV;

Hmm, looking at this again, are you sure this is right?

When ACPI is being used, the version is encoded directly in the driver_data
pointer of the acpi_device_id structure, yet you seem to dereference that
unconditionally here. How are you testing your patch?

Will



More information about the linux-arm-kernel mailing list