All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 3/4] ACPI: replace casts by container_of()
Date: Fri, 8 Jan 2021 14:44:17 +0100	[thread overview]
Message-ID: <4e7f9c14-74c9-b7cc-b788-86cbb7404a58@suse.com> (raw)
In-Reply-To: <9432d21a-004b-c764-25f4-73ff12fd171a@suse.com>

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@suse.com>
---
Intentionally not paying attention to line length in acpi/tables.c, as
adjacent code violates the limit already quite heavily.

--- a/xen/arch/x86/acpi/boot.c
+++ b/xen/arch/x86/acpi/boot.c
@@ -63,9 +63,8 @@ static u64 acpi_lapic_addr __initdata =
 
 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_
 
 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
 
 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 */
--- a/xen/drivers/acpi/tables.c
+++ b/xen/drivers/acpi/tables.c
@@ -55,8 +55,9 @@ void __init acpi_table_print_madt_entry(
 	case ACPI_MADT_TYPE_LOCAL_APIC:
 		if (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(
 	case ACPI_MADT_TYPE_LOCAL_X2APIC:
 		if (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(
 
 	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(
 
 	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(
 
 	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(
 	case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
 		if (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(
 	case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
 		if (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(
 
 	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(
 
 	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(
 	case ACPI_MADT_TYPE_LOCAL_SAPIC:
 		if (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(
 
 	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],



  parent reply	other threads:[~2021-01-08 13:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08 13:41 [PATCH 0/4] x86/ACPI: less verbose logging by default & more Jan Beulich
2021-01-08 13:43 ` [PATCH 1/4] ACPI: reduce verbosity by default Jan Beulich
2021-01-08 13:43 ` [PATCH 2/4] x86/ACPI: don't overwrite FADT Jan Beulich
2021-01-08 13:44 ` Jan Beulich [this message]
2021-01-08 13:44 ` [PATCH 4/4] x86: drop fake CONFIG_{HPET,X86_PM}_TIMER Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e7f9c14-74c9-b7cc-b788-86cbb7404a58@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.