GeezerVison is showing github.com — ACPICA: Apply pack(1) to union aml_resource · frank-w/BPI-Router-Linux@7efa785
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: drivers/acpi/acpica/amlresrc.h +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -504,10 +504,6 @@ struct aml_resource_pin_group_config { | 504 | 504 |
| 505 | 505 | #define AML_RESOURCE_PIN_GROUP_CONFIG_REVISION 1 /* ACPI 6.2 */ | 506 | 506 |
| 507 | | -/* restore default alignment */ | 508 | | - | 509 | | -#pragma pack() | 510 | | - | 511 | 507 | /* Union of all resource descriptors, so we can allocate the worst case */ | 512 | 508 |
| 513 | 509 | union aml_resource { | @@ -562,6 +558,10 @@ union aml_resource { | 562 | 558 | u8 byte_item; | 563 | 559 | }; | 564 | 560 |
| | 561 | +/* restore default alignment */ | | 562 | + | | 563 | +#pragma pack() | | 564 | + | 565 | 565 | /* Interfaces used by both the disassembler and compiler */ | 566 | 566 |
| 567 | 567 | void | |
Collapse file Copy file name to clipboardExpand all lines: drivers/acpi/acpica/rsaddr.c +4-9Lines changed: 4 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 272 | 272 | acpi_rs_get_address_common(struct acpi_resource *resource, | 273 | 273 | union aml_resource *aml) | 274 | 274 | { | 275 | | - struct aml_resource_address address; | 276 | | - | 277 | 275 | ACPI_FUNCTION_ENTRY(); | 278 | 276 |
| 279 | | - /* Avoid undefined behavior: member access within misaligned address */ | 280 | | - | 281 | | - memcpy(&address, aml, sizeof(address)); | 282 | | - | 283 | 277 | /* Validate the Resource Type */ | 284 | 278 |
| 285 | | - if ((address.resource_type > 2) && | 286 | | - (address.resource_type < 0xC0) && (address.resource_type != 0x0A)) { | | 279 | + if ((aml->address.resource_type > 2) && | | 280 | + (aml->address.resource_type < 0xC0) && | | 281 | + (aml->address.resource_type != 0x0A)) { | 287 | 282 | return (FALSE); | 288 | 283 | } | 289 | 284 |
| @@ -304,7 +299,7 @@ acpi_rs_get_address_common(struct acpi_resource *resource, | 304 | 299 | /* Generic resource type, just grab the type_specific byte */ | 305 | 300 |
| 306 | 301 | resource->data.address.info.type_specific = | 307 | | - address.specific_flags; | | 302 | + aml->address.specific_flags; | 308 | 303 | } | 309 | 304 |
| 310 | 305 | return (TRUE); | |
Collapse file Copy file name to clipboardExpand all lines: drivers/acpi/acpica/rscalc.c +5-17Lines changed: 5 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -608,18 +608,12 @@ acpi_rs_get_list_length(u8 *aml_buffer, | 608 | 608 |
| 609 | 609 | case ACPI_RESOURCE_NAME_SERIAL_BUS:{ | 610 | 610 |
| 611 | | - /* Avoid undefined behavior: member access within misaligned address */ | 612 | | - | 613 | | - struct aml_resource_common_serialbus | 614 | | - common_serial_bus; | 615 | | - memcpy(&common_serial_bus, aml_resource, | 616 | | - sizeof(common_serial_bus)); | 617 | | - | 618 | 611 | minimum_aml_resource_length = | 619 | 612 | acpi_gbl_resource_aml_serial_bus_sizes | 620 | | - [common_serial_bus.type]; | | 613 | + [aml_resource->common_serial_bus.type]; | 621 | 614 | extra_struct_bytes += | 622 | | - common_serial_bus.resource_length - | | 615 | + aml_resource->common_serial_bus. | | 616 | + resource_length - | 623 | 617 | minimum_aml_resource_length; | 624 | 618 | break; | 625 | 619 | } | @@ -688,16 +682,10 @@ acpi_rs_get_list_length(u8 *aml_buffer, | 688 | 682 | */ | 689 | 683 | if (acpi_ut_get_resource_type(aml_buffer) == | 690 | 684 | ACPI_RESOURCE_NAME_SERIAL_BUS) { | 691 | | - | 692 | | - /* Avoid undefined behavior: member access within misaligned address */ | 693 | | - | 694 | | - struct aml_resource_common_serialbus common_serial_bus; | 695 | | - memcpy(&common_serial_bus, aml_resource, | 696 | | - sizeof(common_serial_bus)); | 697 | | - | 698 | 685 | buffer_size = | 699 | 686 | acpi_gbl_resource_struct_serial_bus_sizes | 700 | | - [common_serial_bus.type] + extra_struct_bytes; | | 687 | + [aml_resource->common_serial_bus.type] + | | 688 | + extra_struct_bytes; | 701 | 689 | } else { | 702 | 690 | buffer_size = | 703 | 691 | acpi_gbl_resource_struct_sizes[resource_index] + | |
Collapse file Copy file name to clipboardExpand all lines: drivers/acpi/acpica/rslist.c +3-9Lines changed: 3 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,21 +55,15 @@ acpi_rs_convert_aml_to_resources(u8 * aml, | 55 | 55 | aml_resource = ACPI_CAST_PTR(union aml_resource, aml); | 56 | 56 |
| 57 | 57 | if (acpi_ut_get_resource_type(aml) == ACPI_RESOURCE_NAME_SERIAL_BUS) { | 58 | | - | 59 | | - /* Avoid undefined behavior: member access within misaligned address */ | 60 | | - | 61 | | - struct aml_resource_common_serialbus common_serial_bus; | 62 | | - memcpy(&common_serial_bus, aml_resource, | 63 | | - sizeof(common_serial_bus)); | 64 | | - | 65 | | - if (common_serial_bus.type > AML_RESOURCE_MAX_SERIALBUSTYPE) { | | 58 | + if (aml_resource->common_serial_bus.type > | | 59 | + AML_RESOURCE_MAX_SERIALBUSTYPE) { | 66 | 60 | conversion_table = NULL; | 67 | 61 | } else { | 68 | 62 | /* This is an I2C, SPI, UART, or CSI2 serial_bus descriptor */ | 69 | 63 |
| 70 | 64 | conversion_table = | 71 | 65 | acpi_gbl_convert_resource_serial_bus_dispatch | 72 | | - [common_serial_bus.type]; | | 66 | + [aml_resource->common_serial_bus.type]; | 73 | 67 | } | 74 | 68 | } else { | 75 | 69 | conversion_table = | |
Collapse file Copy file name to clipboardExpand all lines: drivers/acpi/acpica/utresrc.c +5-9Lines changed: 5 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -361,20 +361,16 @@ acpi_ut_validate_resource(struct acpi_walk_state *walk_state, | 361 | 361 | aml_resource = ACPI_CAST_PTR(union aml_resource, aml); | 362 | 362 | if (resource_type == ACPI_RESOURCE_NAME_SERIAL_BUS) { | 363 | 363 |
| 364 | | - /* Avoid undefined behavior: member access within misaligned address */ | 365 | | - | 366 | | - struct aml_resource_common_serialbus common_serial_bus; | 367 | | - memcpy(&common_serial_bus, aml_resource, | 368 | | - sizeof(common_serial_bus)); | 369 | | - | 370 | 364 | /* Validate the bus_type field */ | 371 | 365 |
| 372 | | - if ((common_serial_bus.type == 0) || | 373 | | - (common_serial_bus.type > AML_RESOURCE_MAX_SERIALBUSTYPE)) { | | 366 | + if ((aml_resource->common_serial_bus.type == 0) || | | 367 | + (aml_resource->common_serial_bus.type > | | 368 | + AML_RESOURCE_MAX_SERIALBUSTYPE)) { | 374 | 369 | if (walk_state) { | 375 | 370 | ACPI_ERROR((AE_INFO, | 376 | 371 | "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X", | 377 | | - common_serial_bus.type)); | | 372 | + aml_resource->common_serial_bus. | | 373 | + type)); | 378 | 374 | } | 379 | 375 | return (AE_AML_INVALID_RESOURCE_TYPE); | 380 | 376 | } | |
|