[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] ACPI: replace casts by container_of()



commit e945fcf84321547fac36e0d6ad6916daff578fdc
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Mon Jan 11 14:56:23 2021 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Jan 11 14:56:23 2021 +0100

    ACPI: replace casts by container_of()
    
    The latter is slightly more type-safe. Also add const where possible,
    including without need to touch further code. Additionally replace an
    adjacent unnecessary use of u16.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/acpi/boot.c  | 11 +++++----
 xen/drivers/acpi/tables.c | 60 +++++++++++++++++++++++++++--------------------
 2 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/xen/arch/x86/acpi/boot.c b/xen/arch/x86/acpi/boot.c
index 9e857c3ab1..d8c355a02f 100644
--- a/xen/arch/x86/acpi/boot.c
+++ b/xen/arch/x86/acpi/boot.c
@@ -63,9 +63,8 @@ static u64 acpi_lapic_addr __initdata = 
APIC_DEFAULT_PHYS_BASE;
 
 static int __init acpi_parse_madt(struct acpi_table_header *table)
 {
-       struct acpi_table_madt *madt;
-
-       madt = (struct acpi_table_madt *)table;
+       struct acpi_table_madt *madt =
+               container_of(table, struct acpi_table_madt, header);
 
        if (madt->address) {
                acpi_lapic_addr = (u64) madt->address;
@@ -277,7 +276,8 @@ acpi_parse_nmi_src(struct acpi_subtable_header * header, 
const unsigned long end
 
 static int __init acpi_parse_hpet(struct acpi_table_header *table)
 {
-       struct acpi_table_hpet *hpet_tbl = (struct acpi_table_hpet *)table;
+       const struct acpi_table_hpet *hpet_tbl =
+               container_of(table, const struct acpi_table_hpet, header);
 
        if (hpet_tbl->address.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
                printk(KERN_WARNING PREFIX "HPET timers must be located in "
@@ -471,7 +471,8 @@ acpi_fadt_parse_sleep_info(const struct acpi_table_fadt 
*fadt)
 
 static int __init acpi_parse_fadt(struct acpi_table_header *table)
 {
-       struct acpi_table_fadt *fadt = (struct acpi_table_fadt *)table;
+       const struct acpi_table_fadt *fadt =
+               container_of(table, const struct acpi_table_fadt, header);
 
 #ifdef CONFIG_ACPI_INTERPRETER
        /* initialize sci_int early for INT_SRC_OVR MADT parsing */
diff --git a/xen/drivers/acpi/tables.c b/xen/drivers/acpi/tables.c
index 789deef3c1..f39cd5eaac 100644
--- a/xen/drivers/acpi/tables.c
+++ b/xen/drivers/acpi/tables.c
@@ -55,8 +55,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
        case ACPI_MADT_TYPE_LOCAL_APIC:
                if (opt_acpi_verbose)
                {
-                       struct acpi_madt_local_apic *p =
-                           (struct acpi_madt_local_apic *)header;
+                       const struct acpi_madt_local_apic *p =
+                           container_of(header, const struct 
acpi_madt_local_apic, header);
+
                        printk(KERN_INFO PREFIX
                               "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
                               p->processor_id, p->id,
@@ -67,8 +68,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
        case ACPI_MADT_TYPE_LOCAL_X2APIC:
                if (opt_acpi_verbose)
                {
-                       struct acpi_madt_local_x2apic *p =
-                           (struct acpi_madt_local_x2apic *)header;
+                       const struct acpi_madt_local_x2apic *p =
+                           container_of(header, const struct 
acpi_madt_local_x2apic, header);
+
                        printk(KERN_INFO PREFIX
                               "X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
                               p->local_apic_id, p->uid,
@@ -79,8 +81,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
 
        case ACPI_MADT_TYPE_IO_APIC:
                {
-                       struct acpi_madt_io_apic *p =
-                           (struct acpi_madt_io_apic *)header;
+                       const struct acpi_madt_io_apic *p =
+                           container_of(header, const struct 
acpi_madt_io_apic, header);
+
                        printk(KERN_INFO PREFIX
                               "IOAPIC (id[0x%02x] address[0x%08x] 
gsi_base[%d])\n",
                               p->id, p->address, p->global_irq_base);
@@ -89,8 +92,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
 
        case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
                {
-                       struct acpi_madt_interrupt_override *p =
-                           (struct acpi_madt_interrupt_override *)header;
+                       const struct acpi_madt_interrupt_override *p =
+                           container_of(header, const struct 
acpi_madt_interrupt_override, header);
+
                        printk(KERN_INFO PREFIX
                               "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s 
%s)\n",
                               p->bus, p->source_irq, p->global_irq,
@@ -108,8 +112,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
 
        case ACPI_MADT_TYPE_NMI_SOURCE:
                {
-                       struct acpi_madt_nmi_source *p =
-                           (struct acpi_madt_nmi_source *)header;
+                       const struct acpi_madt_nmi_source *p =
+                           container_of(header, const struct 
acpi_madt_nmi_source, header);
+
                        printk(KERN_INFO PREFIX
                               "NMI_SRC (%s %s global_irq %d)\n",
                               mps_inti_flags_polarity[p->inti_flags & 
ACPI_MADT_POLARITY_MASK],
@@ -121,8 +126,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
        case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
                if (opt_acpi_verbose)
                {
-                       struct acpi_madt_local_apic_nmi *p =
-                           (struct acpi_madt_local_apic_nmi *)header;
+                       const struct acpi_madt_local_apic_nmi *p =
+                           container_of(header, const struct 
acpi_madt_local_apic_nmi, header);
+
                        printk(KERN_INFO PREFIX
                               "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[%#x])\n",
                               p->processor_id,
@@ -135,12 +141,10 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
        case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
                if (opt_acpi_verbose)
                {
-                       u16 polarity, trigger;
-                       struct acpi_madt_local_x2apic_nmi *p =
-                           (struct acpi_madt_local_x2apic_nmi *)header;
-
-                       polarity = p->inti_flags & ACPI_MADT_POLARITY_MASK;
-                       trigger = (p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
+                       const struct acpi_madt_local_x2apic_nmi *p =
+                           container_of(header, const struct 
acpi_madt_local_x2apic_nmi, header);
+                       unsigned int polarity = MASK_EXTR(p->inti_flags, 
ACPI_MADT_POLARITY_MASK);
+                       unsigned int trigger = MASK_EXTR(p->inti_flags, 
ACPI_MADT_TRIGGER_MASK);
 
                        printk(KERN_INFO PREFIX
                               "X2APIC_NMI (uid[0x%02x] %s %s lint[%#x])\n",
@@ -153,8 +157,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
 
        case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
                {
-                       struct acpi_madt_local_apic_override *p =
-                           (struct acpi_madt_local_apic_override *)header;
+                       const struct acpi_madt_local_apic_override *p =
+                           container_of(header, const struct 
acpi_madt_local_apic_override, header);
+
                        printk(KERN_INFO PREFIX
                               "LAPIC_ADDR_OVR (address[%p])\n",
                               (void *)(unsigned long)p->address);
@@ -163,8 +168,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
 
        case ACPI_MADT_TYPE_IO_SAPIC:
                {
-                       struct acpi_madt_io_sapic *p =
-                           (struct acpi_madt_io_sapic *)header;
+                       const struct acpi_madt_io_sapic *p =
+                           container_of(header, const struct 
acpi_madt_io_sapic, header);
+
                        printk(KERN_INFO PREFIX
                               "IOSAPIC (id[%#x] address[%p] gsi_base[%d])\n",
                               p->id, (void *)(unsigned long)p->address,
@@ -175,8 +181,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
        case ACPI_MADT_TYPE_LOCAL_SAPIC:
                if (opt_acpi_verbose)
                {
-                       struct acpi_madt_local_sapic *p =
-                           (struct acpi_madt_local_sapic *)header;
+                       const struct acpi_madt_local_sapic *p =
+                           container_of(header, const struct 
acpi_madt_local_sapic, header);
+
                        printk(KERN_INFO PREFIX
                               "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] 
lsapic_eid[0x%02x] %s)\n",
                               p->processor_id, p->id, p->eid,
@@ -186,8 +193,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
 
        case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
                {
-                       struct acpi_madt_interrupt_source *p =
-                           (struct acpi_madt_interrupt_source *)header;
+                       const struct acpi_madt_interrupt_source *p =
+                           container_of(header, const struct 
acpi_madt_interrupt_source, header);
+
                        printk(KERN_INFO PREFIX
                               "PLAT_INT_SRC (%s %s type[%#x] id[0x%04x] 
eid[%#x] iosapic_vector[%#x] global_irq[%#x]\n",
                               mps_inti_flags_polarity[p->inti_flags & 
ACPI_MADT_POLARITY_MASK],
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.