Message ID | 20231129143431.34459-1-liuhaoran14@163.com (mailing list archive) |
---|---|
State | Rejected |
Delegated to: | Geert Uytterhoeven |
Headers | show |
Series | [soc/renesas] renesas-soc: Add error handling in renesas_soc_init | expand |
Hi Haoran, kernel test robot noticed the following build errors: [auto build test ERROR on geert-renesas-devel/next] [also build test ERROR on linus/master v6.7-rc3 next-20231129] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Haoran-Liu/renesas-soc-Add-error-handling-in-renesas_soc_init/20231129-225113 base: https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel.git next patch link: https://lore.kernel.org/r/20231129143431.34459-1-liuhaoran14%40163.com patch subject: [PATCH] [soc/renesas] renesas-soc: Add error handling in renesas_soc_init config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20231130/202311300814.9jXQLQEU-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231130/202311300814.9jXQLQEU-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202311300814.9jXQLQEU-lkp@intel.com/ All errors (new ones prefixed by >>): >> drivers/soc/renesas/renesas-soc.c:492:11: error: use of undeclared identifier 'dev' 492 | dev_err(dev, "Failed to read model property: %d\n", ret); | ^ 1 error generated. vim +/dev +492 drivers/soc/renesas/renesas-soc.c 447 448 static int __init renesas_soc_init(void) 449 { 450 struct soc_device_attribute *soc_dev_attr; 451 unsigned int product, eshi = 0, eslo; 452 const struct renesas_family *family; 453 const struct of_device_id *match; 454 const struct renesas_soc *soc; 455 const struct renesas_id *id; 456 void __iomem *chipid = NULL; 457 const char *rev_prefix = ""; 458 struct soc_device *soc_dev; 459 struct device_node *np; 460 const char *soc_id; 461 int ret; 462 463 match = of_match_node(renesas_socs, of_root); 464 if (!match) 465 return -ENODEV; 466 467 soc_id = strchr(match->compatible, ',') + 1; 468 soc = match->data; 469 family = soc->family; 470 471 np = of_find_matching_node_and_match(NULL, renesas_ids, &match); 472 if (np) { 473 id = match->data; 474 chipid = of_iomap(np, 0); 475 of_node_put(np); 476 } else if (soc->id && family->reg) { 477 /* Try hardcoded CCCR/PRR fallback */ 478 id = &id_prr; 479 chipid = ioremap(family->reg, 4); 480 } 481 482 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); 483 if (!soc_dev_attr) { 484 if (chipid) 485 iounmap(chipid); 486 return -ENOMEM; 487 } 488 489 np = of_find_node_by_path("/"); 490 ret = of_property_read_string(np, "model", &soc_dev_attr->machine); 491 if (ret) { > 492 dev_err(dev, "Failed to read model property: %d\n", ret);
Hi Haoran, Thanks for your patch! On Wed, Nov 29, 2023 at 3:34 PM Haoran Liu <liuhaoran14@163.com> wrote: > 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 Which improper behavior did you encounter? All of the soc_device_attribute fields are optional, and drivers/base/soc.c considers that when handling the machine field (sysfs_emit() handles NULL pointer strings fine). > or incorrect. FTR, "model" is a required property of the root node. > 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@163.com> > --- 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); As reported by the kernel test robot: error: use of undeclared identifier 'dev' Please do not submit completely untested patches. > + kfree(soc_dev_attr); > + return ret; As the machine field is optional, there is no need for this check, let alone to make this a fatal error condition. > + } > + > of_node_put(np); > > soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL); Gr{oetje,eeting}s, Geert
Hi Haoran, kernel test robot noticed the following build errors: [auto build test ERROR on geert-renesas-devel/next] [also build test ERROR on linus/master v6.7-rc3 next-20231201] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Haoran-Liu/renesas-soc-Add-error-handling-in-renesas_soc_init/20231129-225113 base: https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel.git next patch link: https://lore.kernel.org/r/20231129143431.34459-1-liuhaoran14%40163.com patch subject: [PATCH] [soc/renesas] renesas-soc: Add error handling in renesas_soc_init config: openrisc-allyesconfig (https://download.01.org/0day-ci/archive/20231201/202312011703.teVKAipZ-lkp@intel.com/config) compiler: or1k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231201/202312011703.teVKAipZ-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202312011703.teVKAipZ-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from include/linux/device.h:15, from include/linux/sys_soc.h:9, from drivers/soc/renesas/renesas-soc.c:13: drivers/soc/renesas/renesas-soc.c: In function 'renesas_soc_init': >> drivers/soc/renesas/renesas-soc.c:492:25: error: 'dev' undeclared (first use in this function); did you mean 'cdev'? 492 | dev_err(dev, "Failed to read model property: %d\n", ret); | ^~~ include/linux/dev_printk.h:110:25: note: in definition of macro 'dev_printk_index_wrap' 110 | _p_func(dev, fmt, ##__VA_ARGS__); \ | ^~~ drivers/soc/renesas/renesas-soc.c:492:17: note: in expansion of macro 'dev_err' 492 | dev_err(dev, "Failed to read model property: %d\n", ret); | ^~~~~~~ drivers/soc/renesas/renesas-soc.c:492:25: note: each undeclared identifier is reported only once for each function it appears in 492 | dev_err(dev, "Failed to read model property: %d\n", ret); | ^~~ include/linux/dev_printk.h:110:25: note: in definition of macro 'dev_printk_index_wrap' 110 | _p_func(dev, fmt, ##__VA_ARGS__); \ | ^~~ drivers/soc/renesas/renesas-soc.c:492:17: note: in expansion of macro 'dev_err' 492 | dev_err(dev, "Failed to read model property: %d\n", ret); | ^~~~~~~ vim +492 drivers/soc/renesas/renesas-soc.c 447 448 static int __init renesas_soc_init(void) 449 { 450 struct soc_device_attribute *soc_dev_attr; 451 unsigned int product, eshi = 0, eslo; 452 const struct renesas_family *family; 453 const struct of_device_id *match; 454 const struct renesas_soc *soc; 455 const struct renesas_id *id; 456 void __iomem *chipid = NULL; 457 const char *rev_prefix = ""; 458 struct soc_device *soc_dev; 459 struct device_node *np; 460 const char *soc_id; 461 int ret; 462 463 match = of_match_node(renesas_socs, of_root); 464 if (!match) 465 return -ENODEV; 466 467 soc_id = strchr(match->compatible, ',') + 1; 468 soc = match->data; 469 family = soc->family; 470 471 np = of_find_matching_node_and_match(NULL, renesas_ids, &match); 472 if (np) { 473 id = match->data; 474 chipid = of_iomap(np, 0); 475 of_node_put(np); 476 } else if (soc->id && family->reg) { 477 /* Try hardcoded CCCR/PRR fallback */ 478 id = &id_prr; 479 chipid = ioremap(family->reg, 4); 480 } 481 482 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); 483 if (!soc_dev_attr) { 484 if (chipid) 485 iounmap(chipid); 486 return -ENOMEM; 487 } 488 489 np = of_find_node_by_path("/"); 490 ret = of_property_read_string(np, "model", &soc_dev_attr->machine); 491 if (ret) { > 492 dev_err(dev, "Failed to read model property: %d\n", ret);
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);
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@163.com> --- drivers/soc/renesas/renesas-soc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)