]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
soundwire: validate DT compatible before parsing it
authorPengpeng Hou <pengpeng@iscas.ac.cn>
Fri, 3 Apr 2026 06:55:12 +0000 (14:55 +0800)
committerVinod Koul <vkoul@kernel.org>
Sun, 3 May 2026 16:30:08 +0000 (22:00 +0530)
`sdw_of_find_slaves()` fetches raw `"compatible"` bytes with
`of_get_property()` and then immediately parses them with
`sscanf("sdw%01x%04hx%04hx%02hhx", ...)`.

Live-tree OF properties are stored as raw bytes plus a separate length;
they are not globally guaranteed to be NUL-terminated. Validate the
first compatible string before parsing it.

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Link: https://patch.msgid.link/20260403183504.4-soundwire-compatible-pengpeng@iscas.ac.cn
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/slave.c

index ff763b692078dbeb5d03b6cae71575133ab225fd..e0c49cbcb1bab45e7dbe7c8cb8abcc13c4708fb6 100644 (file)
@@ -244,8 +244,8 @@ int sdw_of_find_slaves(struct sdw_bus *bus)
                struct sdw_slave_id id;
                const __be32 *addr;
 
-               compat = of_get_property(node, "compatible", NULL);
-               if (!compat)
+               ret = of_property_read_string(node, "compatible", &compat);
+               if (ret)
                        continue;
 
                ret = sscanf(compat, "sdw%01x%04hx%04hx%02hhx", &sdw_version,