Skip to content

Commit 4435a12

Browse files
arndbrafaeljw
authored andcommitted
ACPI: allow building without CONFIG_HAS_IOPORT
CONFIG_HAS_IOPORT will soon become optional and cause a build time failure when it is disabled but a driver calls inb()/outb(). At the moment, all architectures that can support ACPI have port I/O, but this is not necessarily the case in the future on non-x86 architectures. The result is a set of errors like: drivers/acpi/osl.c: In function 'acpi_os_read_port': include/asm-generic/io.h:542:14: error: call to '_inb' declared with attribute error: inb()) requires CONFIG_HAS_IOPORT Nothing should actually call these functions in this configuration, and if it does, the result would be undefined behavior today, possibly a NULL pointer dereference. Change the low-level functions to return a proper error code when HAS_IOPORT is disabled. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20241030123701.1538919-2-arnd@kernel.org Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 59b723c commit 4435a12

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

drivers/acpi/cppc_acpi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,8 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
10171017
*val = 0;
10181018
size = GET_BIT_WIDTH(reg);
10191019

1020-
if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
1020+
if (IS_ENABLED(CONFIG_HAS_IOPORT) &&
1021+
reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
10211022
u32 val_u32;
10221023
acpi_status status;
10231024

@@ -1091,7 +1092,8 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)
10911092

10921093
size = GET_BIT_WIDTH(reg);
10931094

1094-
if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
1095+
if (IS_ENABLED(CONFIG_HAS_IOPORT) &&
1096+
reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
10951097
acpi_status status;
10961098

10971099
status = acpi_os_write_port((acpi_io_address)reg->address,

drivers/acpi/osl.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,15 @@ acpi_status acpi_os_read_port(acpi_io_address port, u32 *value, u32 width)
642642
{
643643
u32 dummy;
644644

645+
if (!IS_ENABLED(CONFIG_HAS_IOPORT)) {
646+
/*
647+
* set all-1 result as if reading from non-existing
648+
* I/O port
649+
*/
650+
*value = GENMASK(width, 0);
651+
return AE_NOT_IMPLEMENTED;
652+
}
653+
645654
if (value)
646655
*value = 0;
647656
else
@@ -665,6 +674,9 @@ EXPORT_SYMBOL(acpi_os_read_port);
665674

666675
acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
667676
{
677+
if (!IS_ENABLED(CONFIG_HAS_IOPORT))
678+
return AE_NOT_IMPLEMENTED;
679+
668680
if (width <= 8) {
669681
outb(value, port);
670682
} else if (width <= 16) {

0 commit comments

Comments
 (0)