[alsa-devel] [PATCHv2 1/3] ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI builds

Rafael J. Wysocki rjw at rjwysocki.net
Mon Nov 4 02:00:45 CET 2013


On Saturday, November 02, 2013 11:18:31 PM Rafael J. Wysocki wrote:
> On Friday, November 01, 2013 02:35:54 PM Jarkko Nikula wrote:
> > We may find use for struct acpi_device and acpi_bus_get_device() in generic
> > code without wanting to add #if IS_ENABLED(CONFIG_ACPI) churn there.
> > 
> > Code can use ACPI_HANDLE() test to let compiler optimize out code blocks
> > that are not used in !CONFIG_ACPI builds but structure definitions and
> > function stubs must be available.
> > 
> > This patch moves CONFIG_ACPI test so that struct acpi_device definition
> > is available for all builds that include acpi_bus.h and provides a stub for
> > acpi_bus_get_device().
> > 
> > Signed-off-by: Jarkko Nikula <jarkko.nikula at linux.intel.com>
> 
> This turns out the cause build problems to happen on some architectures.
> 
> I guess it's sufficient to simply define a stub struct acpi_device as
> 
> struct acpi_device {
> 	struct device dev;
> };
> 
> for !CONFIG_ACPI instead.

Generally, it is a bad idea to #include acpi_bus.h for !CONFIG_ACPI.

The appended patch works for me, sorry for stealing part of your changelog.

Thanks,
Rafael


---
From: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
Subject: ACPI: Define struct acpi_device for CONFIG_ACPI unset

We may find use for struct acpi_device and acpi_bus_get_device() in
generic code without wanting to add #if IS_ENABLED(CONFIG_ACPI) churn
there.

Code can use ACPI_HANDLE() test to let compiler optimize out code
blocks that are not used in !CONFIG_ACPI builds but structure
definitions and function stubs must be available.

Define a stub struct acpi_device for CONFIG_ACPI unset containing dev
as the only member and a stub acpi_bus_get_device() always returning
an error code.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
---
 include/linux/acpi.h |   10 ++++++++++
 1 file changed, 10 insertions(+)

Index: linux-pm/include/linux/acpi.h
===================================================================
--- linux-pm.orig/include/linux/acpi.h
+++ linux-pm/include/linux/acpi.h
@@ -472,7 +472,17 @@ static inline bool acpi_driver_match_dev
 }
 
 #define ACPI_PTR(_ptr)	(NULL)
+typedef void * acpi_handle;
 
+struct acpi_device {
+	struct device dev;
+};
+
+static inline int acpi_bus_get_device(acpi_handle handle,
+				      struct acpi_device **device)
+{
+	return -ENODEV;
+}
 #endif	/* !CONFIG_ACPI */
 
 #ifdef CONFIG_ACPI



More information about the Alsa-devel mailing list