2023-01-21 21:48:36

by Ashok Raj

[permalink] [raw]
Subject: [Part 2 v2[cleanup] 2/4] x86/microcode: Report invalid writes to reload sysfs file

Currently microcode reload sysfs file only accepts a value of 1. But when
user writes other values we don't report error, but just treat them as
silent success without performing a load.

Report those erroneous writes back to user.

Suggested-by: Thomas Gleixner <[email protected]>
Signed-off-by: Ashok Raj <[email protected]>
Cc: LKML <[email protected]>
Cc: x86 <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Tony Luck <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Alison Schofield <[email protected]>
Cc: Reinette Chatre <[email protected]>
Cc: Thomas Gleixner (Intel) <[email protected]>
Cc: Tom Lendacky <[email protected]>
Cc: Stefan Talpalaru <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Peter Zilstra (Intel) <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Martin Pohlack <[email protected]>
---
arch/x86/kernel/cpu/microcode/core.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index c5d80ff00b4e..6ade3d59c404 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -479,11 +479,8 @@ static ssize_t reload_store(struct device *dev,
ssize_t ret = 0;

ret = kstrtoul(buf, 0, &val);
- if (ret)
- return ret;
-
- if (val != 1)
- return size;
+ if (ret || val != 1)
+ return -EINVAL;

cpus_read_lock();

--
2.34.1