All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Chen <chen.yu@easystack.cn>
To: tglx@linutronix.de, hpa@zytor.com
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	yuchen1988@aliyun.com, Yu Chen <chen.yu@easystack.cn>
Subject: [PATCH] x86/cpuid: Use macro instead of number in cpuid_read()
Date: Thu,  5 Mar 2020 17:33:18 +0800	[thread overview]
Message-ID: <20200305093318.12235-1-chen.yu@easystack.cn> (raw)

Make and use macro CHUNK_SIZE, instead of numeric value 16 in
cpuid_read().

Signed-off-by: Yu Chen <chen.yu@easystack.cn>
---
 arch/x86/kernel/cpuid.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index 3492aa36b..f7d7e0ef7 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -48,6 +48,9 @@ struct cpuid_regs_done {
 	struct completion done;
 };
 
+/* cpuid must be read in chunks of 16 bytes */
+#define CHUNK_SIZE	16
+
 static void cpuid_smp_cpuid(void *cmd_block)
 {
 	struct cpuid_regs_done *cmd = cmd_block;
@@ -69,11 +72,11 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
 	ssize_t bytes = 0;
 	int err = 0;
 
-	if (count % 16)
+	if (count % CHUNK_SIZE)
 		return -EINVAL;	/* Invalid chunk size */
 
 	init_completion(&cmd.done);
-	for (; count; count -= 16) {
+	for (; count; count -= CHUNK_SIZE) {
 		call_single_data_t csd = {
 			.func = cpuid_smp_cpuid,
 			.info = &cmd,
@@ -86,12 +89,12 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
 		if (err)
 			break;
 		wait_for_completion(&cmd.done);
-		if (copy_to_user(tmp, &cmd.regs, 16)) {
+		if (copy_to_user(tmp, &cmd.regs, CHUNK_SIZE)) {
 			err = -EFAULT;
 			break;
 		}
-		tmp += 16;
-		bytes += 16;
+		tmp += CHUNK_SIZE;
+		bytes += CHUNK_SIZE;
 		*ppos = ++pos;
 		reinit_completion(&cmd.done);
 	}
-- 
2.17.1



             reply	other threads:[~2020-03-05  9:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-05  9:33 Yu Chen [this message]
2020-03-05  9:46 ` [PATCH] x86/cpuid: Use macro instead of number in cpuid_read() hpa

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=20200305093318.12235-1-chen.yu@easystack.cn \
    --to=chen.yu@easystack.cn \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yuchen1988@aliyun.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 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.