Patchwork [v2] ACPI / bus: Respect PRP0001 when retrieving device match data

login
register
mail settings
Submitter Andy Shevchenko
Date Feb. 25, 2019, 3:05 p.m.
Message ID <20190225150539.14363-1-andriy.shevchenko@linux.intel.com>
Download mbox | patch
Permalink /patch/735131/
State New
Headers show

Comments

Andy Shevchenko - Feb. 25, 2019, 3:05 p.m.
In case of PRP0001 the compatible string may have additional data affiliated
with the device. When we call device_get_match_data() on such device, we will
get nothing since currently acpi_device_get_match_data() doesn't respect
PRP0001.

To fix above, try acpi_of_match_device() if there is no ACPI table in the
driver.

Anyway, note that the device is supposed to get its own proper ACPI ID.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---

In v2:
 - address Mika's comments

 drivers/acpi/bus.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Sakari Ailus - Feb. 25, 2019, 3:30 p.m.
On Mon, Feb 25, 2019 at 06:05:39PM +0300, Andy Shevchenko wrote:
> In case of PRP0001 the compatible string may have additional data affiliated
> with the device. When we call device_get_match_data() on such device, we will
> get nothing since currently acpi_device_get_match_data() doesn't respect
> PRP0001.
> 
> To fix above, try acpi_of_match_device() if there is no ACPI table in the
> driver.
> 
> Anyway, note that the device is supposed to get its own proper ACPI ID.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Nice one.

Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>

> ---
> 
> In v2:
>  - address Mika's comments
> 
>  drivers/acpi/bus.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index 147f6c7ea59c..6ecbbabf1233 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -799,10 +799,24 @@ const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
>  }
>  EXPORT_SYMBOL_GPL(acpi_match_device);
>  
> +static const void *acpi_of_device_get_match_data(const struct device *dev)
> +{
> +	struct acpi_device *adev = ACPI_COMPANION(dev);
> +	const struct of_device_id *match = NULL;
> +
> +	if (!acpi_of_match_device(adev, dev->driver->of_match_table, &match))
> +		return NULL;
> +
> +	return match->data;
> +}
> +
>  const void *acpi_device_get_match_data(const struct device *dev)
>  {
>  	const struct acpi_device_id *match;
>  
> +	if (!dev->driver->acpi_match_table)
> +		return acpi_of_device_get_match_data(dev);
> +
>  	match = acpi_match_device(dev->driver->acpi_match_table, dev);
>  	if (!match)
>  		return NULL;
> -- 
> 2.20.1
>
Mika Westerberg - Feb. 25, 2019, 7:22 p.m.
On Mon, Feb 25, 2019 at 06:05:39PM +0300, Andy Shevchenko wrote:
> In case of PRP0001 the compatible string may have additional data affiliated
> with the device. When we call device_get_match_data() on such device, we will
> get nothing since currently acpi_device_get_match_data() doesn't respect
> PRP0001.
> 
> To fix above, try acpi_of_match_device() if there is no ACPI table in the
> driver.
> 
> Anyway, note that the device is supposed to get its own proper ACPI ID.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Rafael J. Wysocki - March 1, 2019, 9:25 a.m.
On Mon, Feb 25, 2019 at 8:22 PM Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
>
> On Mon, Feb 25, 2019 at 06:05:39PM +0300, Andy Shevchenko wrote:
> > In case of PRP0001 the compatible string may have additional data affiliated
> > with the device. When we call device_get_match_data() on such device, we will
> > get nothing since currently acpi_device_get_match_data() doesn't respect
> > PRP0001.
> >
> > To fix above, try acpi_of_match_device() if there is no ACPI table in the
> > driver.
> >
> > Anyway, note that the device is supposed to get its own proper ACPI ID.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Patch applied, thanks!

Patch

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 147f6c7ea59c..6ecbbabf1233 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -799,10 +799,24 @@  const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
 }
 EXPORT_SYMBOL_GPL(acpi_match_device);
 
+static const void *acpi_of_device_get_match_data(const struct device *dev)
+{
+	struct acpi_device *adev = ACPI_COMPANION(dev);
+	const struct of_device_id *match = NULL;
+
+	if (!acpi_of_match_device(adev, dev->driver->of_match_table, &match))
+		return NULL;
+
+	return match->data;
+}
+
 const void *acpi_device_get_match_data(const struct device *dev)
 {
 	const struct acpi_device_id *match;
 
+	if (!dev->driver->acpi_match_table)
+		return acpi_of_device_get_match_data(dev);
+
 	match = acpi_match_device(dev->driver->acpi_match_table, dev);
 	if (!match)
 		return NULL;