2022-07-03 15:06:38

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v2 1/1] ASoC: Intel: catpt: remove duplicating driver data retrieval

device_get_match_data() in ACPI case calls similar to acpi_match_device().
Hence there is no need to duplicate the call. Just assign what is in
the id->driver_data.

Signed-off-by: Andy Shevchenko <[email protected]>
---
v2: dropped device_get_match_data() and rewrote commit message
sound/soc/intel/catpt/device.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/sound/soc/intel/catpt/device.c b/sound/soc/intel/catpt/device.c
index 85a34e37316d..2eeaeb962532 100644
--- a/sound/soc/intel/catpt/device.c
+++ b/sound/soc/intel/catpt/device.c
@@ -247,6 +247,7 @@ static int catpt_acpi_probe(struct platform_device *pdev)
id = acpi_match_device(dev->driver->acpi_match_table, dev);
if (!id)
return -ENODEV;
+ spec = (const struct catpt_spec *)id->driver_data;

ret = snd_intel_acpi_dsp_driver_probe(dev, id->id);
if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SST) {
@@ -254,10 +255,6 @@ static int catpt_acpi_probe(struct platform_device *pdev)
return -ENODEV;
}

- spec = device_get_match_data(dev);
- if (!spec)
- return -ENODEV;
-
cdev = devm_kzalloc(dev, sizeof(*cdev), GFP_KERNEL);
if (!cdev)
return -ENOMEM;
--
2.35.1


2022-07-04 07:50:03

by Péter Ujfalusi

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] ASoC: Intel: catpt: remove duplicating driver data retrieval



On 03/07/2022 17:51, Andy Shevchenko wrote:
> device_get_match_data() in ACPI case calls similar to acpi_match_device().
> Hence there is no need to duplicate the call. Just assign what is in
> the id->driver_data.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> v2: dropped device_get_match_data() and rewrote commit message
> sound/soc/intel/catpt/device.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/sound/soc/intel/catpt/device.c b/sound/soc/intel/catpt/device.c
> index 85a34e37316d..2eeaeb962532 100644
> --- a/sound/soc/intel/catpt/device.c
> +++ b/sound/soc/intel/catpt/device.c
> @@ -247,6 +247,7 @@ static int catpt_acpi_probe(struct platform_device *pdev)
> id = acpi_match_device(dev->driver->acpi_match_table, dev);
> if (!id)
> return -ENODEV;
> + spec = (const struct catpt_spec *)id->driver_data;
>
> ret = snd_intel_acpi_dsp_driver_probe(dev, id->id);
> if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SST) {
> @@ -254,10 +255,6 @@ static int catpt_acpi_probe(struct platform_device *pdev)
> return -ENODEV;
> }
>
> - spec = device_get_match_data(dev);
> - if (!spec)
> - return -ENODEV;
> -
> cdev = devm_kzalloc(dev, sizeof(*cdev), GFP_KERNEL);
> if (!cdev)
> return -ENOMEM;

We could just pass the "(const struct catpt_spec *)id->driver_data" in
place of spec to catpt_dev_init() and we can get rid of the local
temporary pointer?

If not, then I would cast out the spec before it's use:
spec = (const struct catpt_spec *)id->driver_data;
catpt_dev_init(cdev, dev, spec);

--
Péter

2022-07-04 16:37:06

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] ASoC: Intel: catpt: remove duplicating driver data retrieval

On Mon, Jul 04, 2022 at 10:36:33AM +0300, P?ter Ujfalusi wrote:
> On 03/07/2022 17:51, Andy Shevchenko wrote:

...

> We could just pass the "(const struct catpt_spec *)id->driver_data" in
> place of spec to catpt_dev_init() and we can get rid of the local
> temporary pointer?

I would not go this way for non-POD types.

> If not, then I would cast out the spec before it's use:
> spec = (const struct catpt_spec *)id->driver_data;
> catpt_dev_init(cdev, dev, spec);

This I can do (as well as in the other patch).

--
With Best Regards,
Andy Shevchenko


2022-07-05 13:32:34

by Cezary Rojewski

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] ASoC: Intel: catpt: remove duplicating driver data retrieval

On 2022-07-04 6:20 PM, Andy Shevchenko wrote:
> On Mon, Jul 04, 2022 at 10:36:33AM +0300, Péter Ujfalusi wrote:
>> On 03/07/2022 17:51, Andy Shevchenko wrote:

...

>> We could just pass the "(const struct catpt_spec *)id->driver_data" in
>> place of spec to catpt_dev_init() and we can get rid of the local
>> temporary pointer?
>
> I would not go this way for non-POD types.


Agree with Andy here.

>> If not, then I would cast out the spec before it's use:
>> spec = (const struct catpt_spec *)id->driver_data;
>> catpt_dev_init(cdev, dev, spec);
>
> This I can do (as well as in the other patch).


Agree with Peter's suggestion here too.


Thank you both for taking time in improving driver's quality!

Regards,
Czarek