[PATCH] [soc/renesas] renesas-soc: Add error handling in renesas_soc_init
From: Haoran Liu
Date: Wed Nov 29 2023 - 09:34:48 EST
This patch enhances the renesas_soc_init function in
drivers/soc/renesas/renesas-soc.c by adding error handling for the
of_property_read_string call. Previously, the function did not check
for failure cases of of_property_read_string, which could lead to
improper behavior if the required device tree properties were missing
or incorrect.
Although the error addressed by this patch may not occur in the current
environment, I still suggest implementing these error handling routines
if the function is not highly time-sensitive. As the environment evolves
or the code gets reused in different contexts, there's a possibility that
these errors might occur. Addressing them now can prevent potential
debugging efforts in the future, which could be quite resource-intensive.
Signed-off-by: Haoran Liu <liuhaoran14@xxxxxxx>
---
drivers/soc/renesas/renesas-soc.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/soc/renesas/renesas-soc.c b/drivers/soc/renesas/renesas-soc.c
index c732d4a5b26a..7a5f5c426118 100644
--- a/drivers/soc/renesas/renesas-soc.c
+++ b/drivers/soc/renesas/renesas-soc.c
@@ -487,7 +487,13 @@ static int __init renesas_soc_init(void)
}
np = of_find_node_by_path("/");
- of_property_read_string(np, "model", &soc_dev_attr->machine);
+ ret = of_property_read_string(np, "model", &soc_dev_attr->machine);
+ if (ret) {
+ dev_err(dev, "Failed to read model property: %d\n", ret);
+ kfree(soc_dev_attr);
+ return ret;
+ }
+
of_node_put(np);
soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
--
2.17.1