linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/cpuid: Use macro instead of number in cpuid_read()
@ 2020-03-05  9:33 Yu Chen
  2020-03-05  9:46 ` hpa
  0 siblings, 1 reply; 2+ messages in thread
From: Yu Chen @ 2020-03-05  9:33 UTC (permalink / raw)
  To: tglx, hpa; +Cc: linux-kernel, x86, yuchen1988, Yu Chen

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86/cpuid: Use macro instead of number in cpuid_read()
  2020-03-05  9:33 [PATCH] x86/cpuid: Use macro instead of number in cpuid_read() Yu Chen
@ 2020-03-05  9:46 ` hpa
  0 siblings, 0 replies; 2+ messages in thread
From: hpa @ 2020-03-05  9:46 UTC (permalink / raw)
  To: Yu Chen, tglx; +Cc: linux-kernel, x86, yuchen1988

On March 5, 2020 1:33:18 AM PST, Yu Chen <chen.yu@easystack.cn> wrote:
>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);
> 	}

It would make more sense to define a structure and add it to a uapi header.
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-05  9:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05  9:33 [PATCH] x86/cpuid: Use macro instead of number in cpuid_read() Yu Chen
2020-03-05  9:46 ` hpa

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).