[PATCH] w1: validate slave string length before checking separator

From: Pengpeng Hou

Date: Tue Jun 30 2026 - 02:59:00 EST


w1_atoreg_num() checks buf[2] for the family/id separator before proving
the input contains that byte.

Require at least the family and separator prefix before checking the
separator.

Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
drivers/w1/w1.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 486f321..c169466 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -403,6 +403,11 @@ static int w1_atoreg_num(struct device *dev, const char *buf, size_t count,
const char *error_msg = "bad slave string format, expecting "
"ff-dddddddddddd\n";

+ if (count < 3) {
+ dev_err(dev, "%s", error_msg);
+ return -EINVAL;
+ }
+
if (buf[2] != '-') {
dev_err(dev, "%s", error_msg);
return -EINVAL;