[PATCH] base: devcoredump: Replace simple_strtol with kstrtol

From: Jiangshan Yi

Date: Mon Jul 20 2026 - 08:56:58 EST


The disabled_store() function uses simple_strtol(), which is marked
obsolete. simple_strtol() does not provide error handling on invalid
input - it silently returns a partial parse result or 0, which the
'if (tmp != 1) return -EINVAL' check then accepts as a legitimate
non-1 value.

Replace simple_strtol(buf, NULL, 10) with kstrtol(buf, 10, &tmp),
which returns an error code on invalid input. This makes the write-once
lockdown attribute stricter: malformed input (e.g. trailing garbage)
now returns -EINVAL instead of being silently treated as a non-1 value
that the caller wanted to reject anyway.

The behaviour for the legitimate '1' input is unchanged.

Signed-off-by: Jiangshan Yi <yijiangshan@xxxxxxxxxx>
---
drivers/base/devcoredump.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
index 8bb1763083dd..f346729bee1b 100644
--- a/drivers/base/devcoredump.c
+++ b/drivers/base/devcoredump.c
@@ -210,7 +210,12 @@ static ssize_t disabled_show(const struct class *class, const struct class_attri
static ssize_t disabled_store(const struct class *class, const struct class_attribute *attr,
const char *buf, size_t count)
{
- long tmp = simple_strtol(buf, NULL, 10);
+ long tmp;
+ int ret;
+
+ ret = kstrtol(buf, 10, &tmp);
+ if (ret < 0)
+ return ret;

/*
* This essentially makes the attribute write-once, since you can't
--
2.25.1