Commit 1d0420f1 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Rafael J. Wysocki

ACPI: Use the length check for io resources as well

Also apply length check to IO resources.

[Jiang] Remove enforcement that resource starting address must be
non-zero.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarJiang Liu <jiang.liu@linux.intel.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent c420dbd1
...@@ -117,31 +117,30 @@ bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res) ...@@ -117,31 +117,30 @@ bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res)
} }
EXPORT_SYMBOL_GPL(acpi_dev_resource_memory); EXPORT_SYMBOL_GPL(acpi_dev_resource_memory);
static unsigned int acpi_dev_ioresource_flags(u64 start, u64 end, u8 io_decode, static void acpi_dev_ioresource_flags(struct resource *res, u64 len,
bool window) u8 io_decode, bool window)
{ {
int flags = IORESOURCE_IO; res->flags = IORESOURCE_IO;
if (io_decode == ACPI_DECODE_16) if (!acpi_dev_resource_len_valid(res->start, res->end, len, true))
flags |= IORESOURCE_IO_16BIT_ADDR; res->flags |= IORESOURCE_DISABLED;
if (start > end || end >= 0x10003) if (res->end >= 0x10003)
flags |= IORESOURCE_DISABLED; res->flags |= IORESOURCE_DISABLED;
if (window) if (io_decode == ACPI_DECODE_16)
flags |= IORESOURCE_WINDOW; res->flags |= IORESOURCE_IO_16BIT_ADDR;
return flags; if (window)
res->flags |= IORESOURCE_WINDOW;
} }
static void acpi_dev_get_ioresource(struct resource *res, u64 start, u64 len, static void acpi_dev_get_ioresource(struct resource *res, u64 start, u64 len,
u8 io_decode) u8 io_decode)
{ {
u64 end = start + len - 1;
res->start = start; res->start = start;
res->end = end; res->end = start + len - 1;
res->flags = acpi_dev_ioresource_flags(start, end, io_decode, false); acpi_dev_ioresource_flags(res, len, io_decode, false);
} }
/** /**
...@@ -161,16 +160,12 @@ bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res) ...@@ -161,16 +160,12 @@ bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res)
switch (ares->type) { switch (ares->type) {
case ACPI_RESOURCE_TYPE_IO: case ACPI_RESOURCE_TYPE_IO:
io = &ares->data.io; io = &ares->data.io;
if (!io->minimum && !io->address_length)
return false;
acpi_dev_get_ioresource(res, io->minimum, acpi_dev_get_ioresource(res, io->minimum,
io->address_length, io->address_length,
io->io_decode); io->io_decode);
break; break;
case ACPI_RESOURCE_TYPE_FIXED_IO: case ACPI_RESOURCE_TYPE_FIXED_IO:
fixed_io = &ares->data.fixed_io; fixed_io = &ares->data.fixed_io;
if (!fixed_io->address && !fixed_io->address_length)
return false;
acpi_dev_get_ioresource(res, fixed_io->address, acpi_dev_get_ioresource(res, fixed_io->address,
fixed_io->address_length, fixed_io->address_length,
ACPI_DECODE_10); ACPI_DECODE_10);
...@@ -178,7 +173,8 @@ bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res) ...@@ -178,7 +173,8 @@ bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res)
default: default:
return false; return false;
} }
return true;
return !(res->flags & IORESOURCE_DISABLED);
} }
EXPORT_SYMBOL_GPL(acpi_dev_resource_io); EXPORT_SYMBOL_GPL(acpi_dev_resource_io);
...@@ -216,9 +212,8 @@ bool acpi_dev_resource_address_space(struct acpi_resource *ares, ...@@ -216,9 +212,8 @@ bool acpi_dev_resource_address_space(struct acpi_resource *ares,
case ACPI_IO_RANGE: case ACPI_IO_RANGE:
io_decode = addr.address.granularity == 0xfff ? io_decode = addr.address.granularity == 0xfff ?
ACPI_DECODE_10 : ACPI_DECODE_16; ACPI_DECODE_10 : ACPI_DECODE_16;
res->flags = acpi_dev_ioresource_flags(addr.address.minimum, acpi_dev_ioresource_flags(res, addr.address.address_length,
addr.address.maximum, io_decode, window);
io_decode, window);
break; break;
case ACPI_BUS_NUMBER_RANGE: case ACPI_BUS_NUMBER_RANGE:
res->flags = IORESOURCE_BUS; res->flags = IORESOURCE_BUS;
...@@ -266,9 +261,8 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, ...@@ -266,9 +261,8 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares,
case ACPI_IO_RANGE: case ACPI_IO_RANGE:
io_decode = ext_addr->address.granularity == 0xfff ? io_decode = ext_addr->address.granularity == 0xfff ?
ACPI_DECODE_10 : ACPI_DECODE_16; ACPI_DECODE_10 : ACPI_DECODE_16;
res->flags = acpi_dev_ioresource_flags(ext_addr->address.minimum, acpi_dev_ioresource_flags(res, ext_addr->address.address_length,
ext_addr->address.maximum, io_decode, window);
io_decode, window);
break; break;
case ACPI_BUS_NUMBER_RANGE: case ACPI_BUS_NUMBER_RANGE:
res->flags = IORESOURCE_BUS; res->flags = IORESOURCE_BUS;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment