diff mbox series

[v1,5/5] ACPI: bus: Use the matching table, if ACPI driver has it

Message ID 20220825164103.27694-5-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v1,1/5] ACPI: bus: Drop kernel doc annotation from acpi_bus_notify() | expand

Commit Message

Andy Shevchenko Aug. 25, 2022, 4:41 p.m. UTC
In case we have an ACPI driver, check its ID table for matching,
This allows to use some generic device property APIs in such
drivers.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/bus.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Comments

Rafael J. Wysocki Aug. 25, 2022, 5:04 p.m. UTC | #1
On Thu, Aug 25, 2022 at 6:41 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> In case we have an ACPI driver, check its ID table for matching,
> This allows to use some generic device property APIs in such
> drivers.

No new provisions for ACPI drivers, please.

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/acpi/bus.c | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index 3c0f2d050d47..17c98e826bde 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -1049,14 +1049,30 @@ static const void *acpi_of_device_get_match_data(const struct device *dev)
>         return match->data;
>  }
>
> +static const struct acpi_device_id *acpi_device_get_ids(const struct device *dev)
> +{
> +       if (dev->driver->acpi_match_table)
> +               return dev->driver->acpi_match_table;
> +
> +       if (dev_is_acpi(dev)) {
> +               struct acpi_driver *drv = to_acpi_driver(dev->driver);
> +
> +               if (drv->ids)
> +                       return drv->ids;
> +       }
> +
> +       return NULL;
> +}
> +
>  const void *acpi_device_get_match_data(const struct device *dev)
>  {
> +       const struct acpi_device_id *ids = acpi_device_get_ids(dev);
>         const struct acpi_device_id *match;
>
> -       if (!dev->driver->acpi_match_table)
> +       if (!ids)
>                 return acpi_of_device_get_match_data(dev);
>
> -       match = acpi_match_device(dev->driver->acpi_match_table, dev);
> +       match = acpi_match_device(ids, dev);
>         if (!match)
>                 return NULL;
>
> --
> 2.35.1
>
Andy Shevchenko Aug. 25, 2022, 5:17 p.m. UTC | #2
On Thu, Aug 25, 2022 at 8:05 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> On Thu, Aug 25, 2022 at 6:41 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > In case we have an ACPI driver, check its ID table for matching,
> > This allows to use some generic device property APIs in such
> > drivers.
>
> No new provisions for ACPI drivers, please.

OK! I will think about how to refactor a driver in question, so it
won't need this kind of trick. Meanwhile patches 1-3 can be applied
independently, if you have no objections.
Andy Shevchenko Aug. 26, 2022, 5:12 p.m. UTC | #3
On Thu, Aug 25, 2022 at 08:17:11PM +0300, Andy Shevchenko wrote:
> On Thu, Aug 25, 2022 at 8:05 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> > On Thu, Aug 25, 2022 at 6:41 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > In case we have an ACPI driver, check its ID table for matching,
> > > This allows to use some generic device property APIs in such
> > > drivers.
> >
> > No new provisions for ACPI drivers, please.
> 
> OK! I will think about how to refactor a driver in question, so it
> won't need this kind of trick. Meanwhile patches 1-3 can be applied
> independently, if you have no objections.

I see that you applied an equivalent patch to what I had here as patch 3.
Taking into account rejection of patches 4 and 5 I will send a v2 with
patch 1 and (modified due to drop of the 5) 2 for your convenience.
Rafael J. Wysocki Aug. 27, 2022, 11:45 a.m. UTC | #4
On Fri, Aug 26, 2022 at 7:12 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Aug 25, 2022 at 08:17:11PM +0300, Andy Shevchenko wrote:
> > On Thu, Aug 25, 2022 at 8:05 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> > > On Thu, Aug 25, 2022 at 6:41 PM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > >
> > > > In case we have an ACPI driver, check its ID table for matching,
> > > > This allows to use some generic device property APIs in such
> > > > drivers.
> > >
> > > No new provisions for ACPI drivers, please.
> >
> > OK! I will think about how to refactor a driver in question, so it
> > won't need this kind of trick. Meanwhile patches 1-3 can be applied
> > independently, if you have no objections.
>
> I see that you applied an equivalent patch to what I had here as patch 3.
> Taking into account rejection of patches 4 and 5 I will send a v2 with
> patch 1 and (modified due to drop of the 5) 2 for your convenience.

Appreciated, thanks!
diff mbox series

Patch

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 3c0f2d050d47..17c98e826bde 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -1049,14 +1049,30 @@  static const void *acpi_of_device_get_match_data(const struct device *dev)
 	return match->data;
 }
 
+static const struct acpi_device_id *acpi_device_get_ids(const struct device *dev)
+{
+	if (dev->driver->acpi_match_table)
+		return dev->driver->acpi_match_table;
+
+	if (dev_is_acpi(dev)) {
+		struct acpi_driver *drv = to_acpi_driver(dev->driver);
+
+		if (drv->ids)
+			return drv->ids;
+	}
+
+	return NULL;
+}
+
 const void *acpi_device_get_match_data(const struct device *dev)
 {
+	const struct acpi_device_id *ids = acpi_device_get_ids(dev);
 	const struct acpi_device_id *match;
 
-	if (!dev->driver->acpi_match_table)
+	if (!ids)
 		return acpi_of_device_get_match_data(dev);
 
-	match = acpi_match_device(dev->driver->acpi_match_table, dev);
+	match = acpi_match_device(ids, dev);
 	if (!match)
 		return NULL;