Skip to contentSkip to conversation

x86/cpuid: Use macro instead of number in cpuid_read()

PATCH In review Yu Chen 2 participants 2 messages Mar 5, 2020

Subsystems (2)
lore
Share & tools
lore

Yu Chen

author
#0 lore raw

PATCH 1/1 x86/cpuid: Use macro instead of number in cpuid_read()

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

---
 arch/x86/kernel/cpuid.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/x86/kernel/cpuid.c +8 -5
index 3492aa36b..f7d7e0ef7 100644
@@ -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);
 	}
Signature · 1 line
2.17.1
#1 lore raw
Quoted 53 lines · Yu Chen

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

---
arch/x86/kernel/cpuid.c | 13 ++++++++-----

1 file changed, 8 insertions(+), 5 deletions(-)
arch/x86/kernel/cpuid.c +5 -2
index 3492aa36b..f7d7e0ef7 100644
@@ -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,
arch/x86/kernel/cpuid.c +3 -3
@@ -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);
Quoted 1 line
	}

It would make more sense to define a structure and add it to a uapi header.

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.