Skip to content

Commit 74522fe

Browse files
keesrafaeljw
authored andcommitted
ACPICA: actbl2: Replace 1-element arrays with flexible arrays
ACPICA commit 44f1af0664599e87bebc3a1260692baa27b2f264 Similar to "Replace one-element array with flexible-array", replace the 1-element array with a proper flexible array member as defined by C99. This allows the code to operate without tripping compile-time and run- time bounds checkers (e.g. via __builtin_object_size(), -fsanitize=bounds, and/or -fstrict-flex-arrays=3). The sizeof() uses with struct acpi_nfit_flush_address and struct acpi_nfit_smbios have been adjusted to drop the open-coded subtraction of the trailing single element. The result is no binary differences in .text nor .data sections. Link: acpica/acpica@44f1af06 Signed-off-by: Bob Moore <robert.moore@intel.com> Co-developed-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 48ff467 commit 74522fe

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

drivers/acpi/nfit/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ static size_t sizeof_flush(struct acpi_nfit_flush_address *flush)
894894
{
895895
if (flush->header.length < sizeof(*flush))
896896
return 0;
897-
return sizeof(*flush) + sizeof(u64) * (flush->hint_count - 1);
897+
return struct_size(flush, hint_address, flush->hint_count);
898898
}
899899

900900
static bool add_flush(struct acpi_nfit_desc *acpi_desc,
@@ -3477,7 +3477,7 @@ static __init int nfit_init(void)
34773477
BUILD_BUG_ON(sizeof(struct acpi_nfit_system_address) != 64);
34783478
BUILD_BUG_ON(sizeof(struct acpi_nfit_memory_map) != 48);
34793479
BUILD_BUG_ON(sizeof(struct acpi_nfit_interleave) != 20);
3480-
BUILD_BUG_ON(sizeof(struct acpi_nfit_smbios) != 9);
3480+
BUILD_BUG_ON(sizeof(struct acpi_nfit_smbios) != 8);
34813481
BUILD_BUG_ON(sizeof(struct acpi_nfit_control_region) != 80);
34823482
BUILD_BUG_ON(sizeof(struct acpi_nfit_data_region) != 40);
34833483
BUILD_BUG_ON(sizeof(struct acpi_nfit_capabilities) != 16);

include/acpi/actbl2.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ struct acpi_iort_node {
397397
u32 identifier;
398398
u32 mapping_count;
399399
u32 mapping_offset;
400-
char node_data[1];
400+
char node_data[];
401401
};
402402

403403
/* Values for subtable Type above */
@@ -453,14 +453,14 @@ struct acpi_iort_memory_access {
453453
*/
454454
struct acpi_iort_its_group {
455455
u32 its_count;
456-
u32 identifiers[1]; /* GIC ITS identifier array */
456+
u32 identifiers[]; /* GIC ITS identifier array */
457457
};
458458

459459
struct acpi_iort_named_component {
460460
u32 node_flags;
461461
u64 memory_properties; /* Memory access properties */
462462
u8 memory_address_limit; /* Memory address size limit */
463-
char device_name[1]; /* Path of namespace object */
463+
char device_name[]; /* Path of namespace object */
464464
};
465465

466466
/* Masks for Flags field above */
@@ -474,7 +474,7 @@ struct acpi_iort_root_complex {
474474
u32 pci_segment_number;
475475
u8 memory_address_limit; /* Memory address size limit */
476476
u16 pasid_capabilities; /* PASID Capabilities */
477-
u8 reserved[1]; /* Reserved, must be zero */
477+
u8 reserved[]; /* Reserved, must be zero */
478478
};
479479

480480
/* Masks for ats_attribute field above */
@@ -496,7 +496,7 @@ struct acpi_iort_smmu {
496496
u32 context_interrupt_offset;
497497
u32 pmu_interrupt_count;
498498
u32 pmu_interrupt_offset;
499-
u64 interrupts[1]; /* Interrupt array */
499+
u64 interrupts[]; /* Interrupt array */
500500
};
501501

502502
/* Values for Model field above */
@@ -975,7 +975,7 @@ struct acpi_madt_local_sapic {
975975
u8 reserved[3]; /* Reserved, must be zero */
976976
u32 lapic_flags;
977977
u32 uid; /* Numeric UID - ACPI 3.0 */
978-
char uid_string[1]; /* String UID - ACPI 3.0 */
978+
char uid_string[]; /* String UID - ACPI 3.0 */
979979
};
980980

981981
/* 8: Platform Interrupt Source */
@@ -1708,7 +1708,7 @@ struct acpi_nfit_interleave {
17081708
struct acpi_nfit_smbios {
17091709
struct acpi_nfit_header header;
17101710
u32 reserved; /* Reserved, must be zero */
1711-
u8 data[1]; /* Variable length */
1711+
u8 data[]; /* Variable length */
17121712
};
17131713

17141714
/* 4: NVDIMM Control Region Structure */
@@ -1765,7 +1765,7 @@ struct acpi_nfit_flush_address {
17651765
u32 device_handle;
17661766
u16 hint_count;
17671767
u8 reserved[6]; /* Reserved, must be zero */
1768-
u64 hint_address[1]; /* Variable length */
1768+
u64 hint_address[]; /* Variable length */
17691769
};
17701770

17711771
/* 7: Platform Capabilities Structure */

tools/testing/nvdimm/test/nfit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,14 +1878,14 @@ static size_t sizeof_spa(struct acpi_nfit_system_address *spa)
18781878
static int nfit_test0_alloc(struct nfit_test *t)
18791879
{
18801880
struct acpi_nfit_system_address *spa = NULL;
1881+
struct acpi_nfit_flush_address *flush;
18811882
size_t nfit_size = sizeof_spa(spa) * NUM_SPA
18821883
+ sizeof(struct acpi_nfit_memory_map) * NUM_MEM
18831884
+ sizeof(struct acpi_nfit_control_region) * NUM_DCR
18841885
+ offsetof(struct acpi_nfit_control_region,
18851886
window_size) * NUM_DCR
18861887
+ sizeof(struct acpi_nfit_data_region) * NUM_BDW
1887-
+ (sizeof(struct acpi_nfit_flush_address)
1888-
+ sizeof(u64) * NUM_HINTS) * NUM_DCR
1888+
+ struct_size(flush, hint_address, NUM_HINTS) * NUM_DCR
18891889
+ sizeof(struct acpi_nfit_capabilities);
18901890
int i;
18911891

0 commit comments

Comments
 (0)