LoongArch: Avoid in-place string operation on FDT content
authorYao Zi <ziyao@disroot.org>
Sun, 3 Aug 2025 14:49:47 +0000 (22:49 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Sun, 3 Aug 2025 14:49:47 +0000 (22:49 +0800)
commit70a2365e18affc5ebdaab1ca6a0b3c4f3aac2ee8
tree36ea132d6cb67d206ef07c950bc4790449506246
parent243f8de49f076d56ee88d6f03b6221984cc63668
LoongArch: Avoid in-place string operation on FDT content

In init_cpu_fullname(), a constant pointer to "model" property is
retrieved. It's later modified by the strsep() function, which is
illegal and corrupts kernel's FDT copy. This is shown by dmesg,

OF: fdt: not creating '/sys/firmware/fdt': CRC check failed

Create a mutable copy of the model property and do in-place operations
on the mutable copy instead. loongson_sysconf.cpuname lives across the
kernel lifetime, thus manually releasing isn't necessary.

Also move the of_node_put() call for the root node after the usage of
its property, since of_node_put() decreases the reference counter thus
usage after the call is unsafe.

Cc: stable@vger.kernel.org
Fixes: 44a01f1f726a ("LoongArch: Parsing CPU-related information from DTS")
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Yao Zi <ziyao@disroot.org>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kernel/env.c