public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Jay Lu <jaylu102@amd.com>
To: <jaylu102@amd.com>, <linux-kernel@vger.kernel.org>,
	<rafael@kernel.org>, <lenb@kernel.org>, <james.morse@arm.com>,
	<tony.luck@intel.com>, <bp@alien8.de>,
	<dave.hansen@linux.intel.com>, <jarkko@kernel.org>,
	<xueshuai@linux.alibaba.com>
Cc: <terry.bowman@amd.com>, <yazen.ghannam@amd.com>,
	<smita.koralahallichannabasappa@amd.com>,
	<robert.richter@amd.com>, <linux-acpi@vger.kernel.org>,
	<jayakumar.govindankalivu@amd.com>
Subject: [PATCH 2/3] ACPI, APEI, EINJ: Refactor available_error_type_show
Date: Fri, 29 Jul 2022 10:35:49 -0500	[thread overview]
Message-ID: <20220729153550.181209-3-jaylu102@amd.com> (raw)
In-Reply-To: <20220729153550.181209-1-jaylu102@amd.com>

Move error type descriptions into an array and loop over error types
to improve readability and maintainability.

Replace seq_printf() with seq_puts() as recommended by checkpatch.pl.

Signed-off-by: Jay Lu <jaylu102@amd.com>
---
 drivers/acpi/apei/einj.c | 41 +++++++++++++++++-----------------------
 1 file changed, 17 insertions(+), 24 deletions(-)

diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
index da039c630fd0..a68103280f74 100644
--- a/drivers/acpi/apei/einj.c
+++ b/drivers/acpi/apei/einj.c
@@ -569,6 +569,20 @@ static u64 error_param2;
 static u64 error_param3;
 static u64 error_param4;
 static struct dentry *einj_debug_dir;
+static const char * const einj_error_type_string[] = {
+	"0x00000001\tProcessor Correctable\n",                          /* bit 0  */
+	"0x00000002\tProcessor Uncorrectable non-fatal\n",              /* bit 1  */
+	"0x00000004\tProcessor Uncorrectable fatal\n",                  /* bit 2  */
+	"0x00000008\tMemory Correctable\n",                             /* bit 3  */
+	"0x00000010\tMemory Uncorrectable non-fatal\n",                 /* bit 4  */
+	"0x00000020\tMemory Uncorrectable fatal\n",                     /* bit 5  */
+	"0x00000040\tPCI Express Correctable\n",                        /* bit 6  */
+	"0x00000080\tPCI Express Uncorrectable non-fatal\n",            /* bit 7  */
+	"0x00000100\tPCI Express Uncorrectable fatal\n",                /* bit 8  */
+	"0x00000200\tPlatform Correctable\n",                           /* bit 9  */
+	"0x00000400\tPlatform Uncorrectable non-fatal\n",               /* bit 10 */
+	"0x00000800\tPlatform Uncorrectable fatal\n",                   /* bit 11 */
+};
 
 static int available_error_type_show(struct seq_file *m, void *v)
 {
@@ -578,30 +592,9 @@ static int available_error_type_show(struct seq_file *m, void *v)
 	rc = einj_get_available_error_type(&available_error_type);
 	if (rc)
 		return rc;
-	if (available_error_type & 0x0001)
-		seq_printf(m, "0x00000001\tProcessor Correctable\n");
-	if (available_error_type & 0x0002)
-		seq_printf(m, "0x00000002\tProcessor Uncorrectable non-fatal\n");
-	if (available_error_type & 0x0004)
-		seq_printf(m, "0x00000004\tProcessor Uncorrectable fatal\n");
-	if (available_error_type & 0x0008)
-		seq_printf(m, "0x00000008\tMemory Correctable\n");
-	if (available_error_type & 0x0010)
-		seq_printf(m, "0x00000010\tMemory Uncorrectable non-fatal\n");
-	if (available_error_type & 0x0020)
-		seq_printf(m, "0x00000020\tMemory Uncorrectable fatal\n");
-	if (available_error_type & 0x0040)
-		seq_printf(m, "0x00000040\tPCI Express Correctable\n");
-	if (available_error_type & 0x0080)
-		seq_printf(m, "0x00000080\tPCI Express Uncorrectable non-fatal\n");
-	if (available_error_type & 0x0100)
-		seq_printf(m, "0x00000100\tPCI Express Uncorrectable fatal\n");
-	if (available_error_type & 0x0200)
-		seq_printf(m, "0x00000200\tPlatform Correctable\n");
-	if (available_error_type & 0x0400)
-		seq_printf(m, "0x00000400\tPlatform Uncorrectable non-fatal\n");
-	if (available_error_type & 0x0800)
-		seq_printf(m, "0x00000800\tPlatform Uncorrectable fatal\n");
+	for (int pos = 0; pos < ARRAY_SIZE(einj_error_type_string); pos++)
+		if (available_error_type & (BIT(0) << pos))
+			seq_puts(m, einj_error_type_string[pos]);
 
 	return 0;
 }
-- 
2.27.0


  parent reply	other threads:[~2022-07-29 15:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-29 15:35 [PATCH 0/3] ACPI, APEI, EINJ: Add new CXL Error Types Jay Lu
2022-07-29 15:35 ` [PATCH 1/3] ACPI, APEI, EINJ: Fix Formatting Errors Jay Lu
2022-07-29 15:35 ` Jay Lu [this message]
2022-09-20  9:26   ` [PATCH 2/3] ACPI, APEI, EINJ: Refactor available_error_type_show Borislav Petkov
2022-07-29 15:35 ` [PATCH 3/3] ACPI, APEI, EINJ: Add support for new CXL error types Jay Lu
2022-11-30 20:20 ` [PATCH 0/3] ACPI, APEI, EINJ: Add new CXL Error Types Ben Cheatham

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=20220729153550.181209-3-jaylu102@amd.com \
    --to=jaylu102@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=james.morse@arm.com \
    --cc=jarkko@kernel.org \
    --cc=jayakumar.govindankalivu@amd.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=robert.richter@amd.com \
    --cc=smita.koralahallichannabasappa@amd.com \
    --cc=terry.bowman@amd.com \
    --cc=tony.luck@intel.com \
    --cc=xueshuai@linux.alibaba.com \
    --cc=yazen.ghannam@amd.com \
    /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