public inbox for loongarch@lists.linux.dev
 help / color / mirror / Atom feed
From: George Guo <dongtai.guo@linux.dev>
To: chenhuacai@kernel.org, joe@perches.com
Cc: guodongtai@kylinos.cn, kernel@xen0n.name, hengqi.chen@gmail.com,
	loongarch@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] LoongArch: proc: Simplify cpuinfo features output
Date: Sat, 28 Feb 2026 18:29:46 +0800	[thread overview]
Message-ID: <20260228102946.4045-1-dongtai.guo@linux.dev> (raw)

From: George Guo <guodongtai@kylinos.cn>

Introduce seq_cpu_feature() macro to eliminate repetitive if statements
in show_cpuinfo(). The macro expands to:
    do {
        if (cpu_has_##feature)
            seq_puts(m, " " #feature);
    } while (0)

This improves code readability and maintainability.

Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
 arch/loongarch/kernel/proc.c | 56 ++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 32 deletions(-)

diff --git a/arch/loongarch/kernel/proc.c b/arch/loongarch/kernel/proc.c
index a8127e83da65..4742bdfc3872 100644
--- a/arch/loongarch/kernel/proc.c
+++ b/arch/loongarch/kernel/proc.c
@@ -13,6 +13,12 @@
 #include <asm/processor.h>
 #include <asm/time.h>
 
+#define seq_cpu_feature(m, feature)		\
+do {						\
+	if (cpu_has_##feature)			\
+		seq_puts(m, " " #feature);	\
+} while (0)
+
 static int show_cpuinfo(struct seq_file *m, void *v)
 {
 	unsigned long n = (unsigned long) v - 1;
@@ -60,38 +66,24 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 	seq_puts(m, "\n");
 
 	seq_puts(m, "Features\t\t:");
-	if (cpu_has_cpucfg)
-		seq_puts(m, " cpucfg");
-	if (cpu_has_lam)
-		seq_puts(m, " lam");
-	if (cpu_has_scq)
-		seq_puts(m, " scq");
-	if (cpu_has_ual)
-		seq_puts(m, " ual");
-	if (cpu_has_fpu)
-		seq_puts(m, " fpu");
-	if (cpu_has_lsx)
-		seq_puts(m, " lsx");
-	if (cpu_has_lasx)
-		seq_puts(m, " lasx");
-	if (cpu_has_crc32)
-		seq_puts(m, " crc32");
-	if (cpu_has_complex)
-		seq_puts(m, " complex");
-	if (cpu_has_crypto)
-		seq_puts(m, " crypto");
-	if (cpu_has_ptw)
-		seq_puts(m, " ptw");
-	if (cpu_has_lspw)
-		seq_puts(m, " lspw");
-	if (cpu_has_lvz)
-		seq_puts(m, " lvz");
-	if (cpu_has_lbt_x86)
-		seq_puts(m, " lbt_x86");
-	if (cpu_has_lbt_arm)
-		seq_puts(m, " lbt_arm");
-	if (cpu_has_lbt_mips)
-		seq_puts(m, " lbt_mips");
+
+	seq_cpu_feature(m, cpucfg);
+	seq_cpu_feature(m, lam);
+	seq_cpu_feature(m, scq);
+	seq_cpu_feature(m, ual);
+	seq_cpu_feature(m, fpu);
+	seq_cpu_feature(m, lsx);
+	seq_cpu_feature(m, lasx);
+	seq_cpu_feature(m, crc32);
+	seq_cpu_feature(m, complex);
+	seq_cpu_feature(m, crypto);
+	seq_cpu_feature(m, ptw);
+	seq_cpu_feature(m, lspw);
+	seq_cpu_feature(m, lvz);
+	seq_cpu_feature(m, lbt_x86);
+	seq_cpu_feature(m, lbt_arm);
+	seq_cpu_feature(m, lbt_mips);
+
 	seq_puts(m, "\n");
 
 	seq_printf(m, "Hardware Watchpoint\t: %s", str_yes_no(cpu_has_watch));
-- 
2.34.1


                 reply	other threads:[~2026-02-28 10:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260228102946.4045-1-dongtai.guo@linux.dev \
    --to=dongtai.guo@linux.dev \
    --cc=chenhuacai@kernel.org \
    --cc=guodongtai@kylinos.cn \
    --cc=hengqi.chen@gmail.com \
    --cc=joe@perches.com \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    /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