linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cao jin <caoj.fnst@cn.fujitsu.com>
To: <x86@kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: <rjw@rjwysocki.net>, <len.brown@intel.com>, <pavel@ucw.cz>,
	<tglx@linutronix.de>, <mingo@redhat.com>, <hpa@zytor.com>
Subject: [RFC PATCH 2/2] x86/acpi: Cleanup acpi_process_madt()
Date: Thu, 23 Jan 2020 09:32:38 +0800	[thread overview]
Message-ID: <20200123013238.19059-3-caoj.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20200123013238.19059-1-caoj.fnst@cn.fujitsu.com>

After many duct-taped patches, the readablity of these code chunks are
really hard. This patch does following improvements:

  1. Drop unnecessary comment that is self-documented by function name,
     while supply with necessary comments.
  2. Drop duplicated code: acpi_process_madt() has already been called
     in early madt processing, acpi_lapic & smp_found_config is also
     initialized there.
  3. Fix code logic: variable count's usage is quite confusing now, and
     some code logic is wrong, like count & x2count will never be negative
     after assigned from madt_proc[n].count

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
 arch/x86/kernel/acpi/boot.c | 44 +++++++++++++++----------------------
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 2131035bba98..844fc9f26064 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -1026,9 +1026,10 @@ static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
 	return count;
 }
 
+/* Returns 0 on success, < 0 on error. */
 static int __init acpi_parse_madt_lapic_entries(void)
 {
-	int count;
+	int count = 0;
 	int x2count = 0;
 	int ret;
 	struct acpi_subtable_proc madt_proc[2];
@@ -1036,10 +1037,13 @@ static int __init acpi_parse_madt_lapic_entries(void)
 	if (!boot_cpu_has(X86_FEATURE_APIC))
 		return -ENODEV;
 
-	count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
-				      acpi_parse_sapic, MAX_LOCAL_APIC);
+	/* SAPIC is commonly found on Intel Itanium processor. */
+	ret = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
+				    acpi_parse_sapic, MAX_LOCAL_APIC);
 
-	if (!count) {
+
+	/* No SAPIC entries implies it is not Itanium processor. */
+	if (!ret) {
 		memset(madt_proc, 0, sizeof(madt_proc));
 		madt_proc[0].id = ACPI_MADT_TYPE_LOCAL_APIC;
 		madt_proc[0].handler = acpi_parse_lapic;
@@ -1056,15 +1060,14 @@ static int __init acpi_parse_madt_lapic_entries(void)
 
 		count = madt_proc[0].count;
 		x2count = madt_proc[1].count;
-	}
-	if (!count && !x2count) {
-		printk(KERN_ERR PREFIX "No LAPIC entries present\n");
-		/* TBD: Cleanup to allow fallback to MPS */
-		return -ENODEV;
-	} else if (count < 0 || x2count < 0) {
-		printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
-		/* TBD: Cleanup to allow fallback to MPS */
-		return count;
+		if (!count && !x2count) {
+			printk(KERN_ERR PREFIX "No LAPIC entries present\n");
+			/* TBD: Cleanup to allow fallback to MPS */
+			return -ENODEV;
+		}
+	} else if (ret < 0) {
+		printk(KERN_ERR PREFIX "Error parsing SAPIC entries\n");
+		return ret;
 	}
 
 	x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
@@ -1074,7 +1077,7 @@ static int __init acpi_parse_madt_lapic_entries(void)
 	if (count < 0 || x2count < 0) {
 		printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
 		/* TBD: Cleanup to allow fallback to MPS */
-		return count;
+		return (count < 0) ? count : x2count;
 	}
 	return 0;
 }
@@ -1255,25 +1258,14 @@ static void __init acpi_process_madt(void)
 #ifdef CONFIG_X86_LOCAL_APIC
 	int error;
 
-	if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
-
-		/*
-		 * Parse MADT LAPIC entries
-		 */
+	if (acpi_lapic) {
 		error = acpi_parse_madt_lapic_entries();
 		if (!error) {
-			acpi_lapic = 1;
-
-			/*
-			 * Parse MADT IO-APIC entries
-			 */
 			mutex_lock(&acpi_ioapic_lock);
 			error = acpi_parse_madt_ioapic_entries();
 			mutex_unlock(&acpi_ioapic_lock);
 			if (!error) {
 				acpi_set_irq_model_ioapic();
-
-				smp_found_config = 1;
 			}
 		}
 		if (error == -EINVAL) {
-- 
2.21.0




  parent reply	other threads:[~2020-01-23  1:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23  1:32 [RFC PATCH 0/2] x86/boot: early ACPI MADT processing cleanup Cao jin
2020-01-23  1:32 ` [RFC PATCH 1/2] x86/acpi: Improve code readablity of early madt processing Cao jin
2020-01-23  1:32 ` Cao jin [this message]
2020-01-23  1:43 ` [RFC PATCH 0/2] x86/boot: early ACPI MADT processing cleanup Cao jin
  -- strict thread matches above, loose matches on Subject: below --
2020-01-23  1:41 Cao jin
2020-01-23  1:41 ` [RFC PATCH 2/2] x86/acpi: Cleanup acpi_process_madt() Cao jin
2020-01-22  3:47 [RFC PATCH 0/2] x86/boot: early ACPI MADT processing cleanup Cao jin
2020-01-22  3:47 ` [RFC PATCH 2/2] x86/acpi: Cleanup acpi_process_madt() Cao jin

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=20200123013238.19059-3-caoj.fnst@cn.fujitsu.com \
    --to=caoj.fnst@cn.fujitsu.com \
    --cc=hpa@zytor.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).