aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanyuan Zhao <hanyuan-z@qq.com>2024-05-06 17:10:06 +0800
committerLeo Yu-Chi Liang <ycliang@andestech.com>2024-05-14 18:39:57 +0800
commit9578e74571596eb8f1a74b46cbb2ddf6ed5dee39 (patch)
treebf856da2c99696e8853a6e740f5fe10545cce842
parentc8ffd1356d42223cbb8c86280a083cc3c93e6426 (diff)
downloadu-boot-9578e74571596eb8f1a74b46cbb2ddf6ed5dee39.zip
u-boot-9578e74571596eb8f1a74b46cbb2ddf6ed5dee39.tar.gz
u-boot-9578e74571596eb8f1a74b46cbb2ddf6ed5dee39.tar.bz2
riscv: add NULL check before calling strlen in the riscv cpu's get_desc()
Without the NULL check, if the devicetree that u-boot loads does not have a compatible property then a store access fault will be raised and force the machine to reset, due to the NULL pointer we passed to strlen. This commit adds this check and will return -ENOSPC to indicate the get_desc failed. Signed-off-by: Hanyuan Zhao <zhaohy22@mails.tsinghua.edu.cn> Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
-rw-r--r--drivers/cpu/riscv_cpu.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/cpu/riscv_cpu.c b/drivers/cpu/riscv_cpu.c
index 4f2958a..4fff465 100644
--- a/drivers/cpu/riscv_cpu.c
+++ b/drivers/cpu/riscv_cpu.c
@@ -23,7 +23,7 @@ static int riscv_cpu_get_desc(const struct udevice *dev, char *buf, int size)
const char *cpu;
cpu = dev_read_string(dev, "compatible");
- if (size < (strlen(cpu) + 1))
+ if (!cpu || size < (strlen(cpu) + 1))
return -ENOSPC;
strcpy(buf, cpu);