Re: [PATCH] fix: mfd: of_syscon_register: fix reset_control reference leak on success path
kernel test robot <[email protected]>
| Newsgroups | dev.linux.lists.llvm,dev.linux.lists.oe-kbuild-all,org.kernel.vger.linux-kernel,org.kernel.vger.stable |
|---|---|
| Message-ID | <[email protected]> |
Hi WenTao, kernel test robot noticed the following build warnings: [auto build test WARNING on lee-mfd/for-mfd-next] [also build test WARNING on lee-mfd/for-mfd-fixes lee-leds/for-leds-next linus/master v7.2-rc6 next-20260807] [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/WenTao-Liang/fix-mfd-of_syscon_register-fix-reset_control-reference-leak-on-success-path/20260807-005058 base: https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next patch link: https://lore.kernel.org/r/20260626151125.50780-1-vulab%40iscas.ac.cn patch subject: [PATCH] fix: mfd: of_syscon_register: fix reset_control reference leak on success path config: loongarch-defconfig (https://download.01.org/0day-ci/archive/20260808/[email protected]/config) compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 12df34b8469b8095359de8c249cb1b2753fadeea) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260808/[email protected]/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 <[email protected]> | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ All warnings (new ones prefixed by >>): >> drivers/mfd/syscon.c:125:6: warning: variable 'reset' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] 125 | if (check_res) { | ^~~~~~~~~ drivers/mfd/syscon.c:151:18: note: uninitialized use occurs here 151 | syscon->reset = reset; | ^~~~~ drivers/mfd/syscon.c:125:2: note: remove the 'if' if its condition is always true 125 | if (check_res) { | ^~~~~~~~~~~~~~ drivers/mfd/syscon.c:49:29: note: initialize the variable 'reset' to silence this warning 49 | struct reset_control *reset; | ^ | = NULL 1 warning generated. vim +125 drivers/mfd/syscon.c 87d687301f3807 Dong Aisheng 2012-09-05 39 7d1e3bd94828ad Jeremy Kerr 2023-01-05 40 static struct syscon *of_syscon_register(struct device_node *np, bool check_res) 87d687301f3807 Dong Aisheng 2012-09-05 41 { a00406b71c5f08 Fabrice Gasnier 2018-12-12 42 struct clk *clk; bdb0066df96e74 Pankaj Dubey 2014-09-30 43 struct regmap *regmap; bdb0066df96e74 Pankaj Dubey 2014-09-30 44 void __iomem *base; db2fb60cd35d2d Damien Riegel 2015-11-30 45 u32 reg_io_width; bdb0066df96e74 Pankaj Dubey 2014-09-30 46 int ret; bdb0066df96e74 Pankaj Dubey 2014-09-30 47 struct regmap_config syscon_config = syscon_regmap_config; ca668f0edfae65 Philipp Zabel 2016-01-29 48 struct resource res; 7d1e3bd94828ad Jeremy Kerr 2023-01-05 49 struct reset_control *reset; ba09916efb29f8 Eder Zulian 2025-02-12 50 resource_size_t res_size; bdb0066df96e74 Pankaj Dubey 2014-09-30 51 805f7aaf7fee14 Rob Herring (Arm 2024-12-17 52) WARN_ON(!mutex_is_locked(&syscon_list_lock)); 805f7aaf7fee14 Rob Herring (Arm 2024-12-17 53) bf4afc53b77aea Linus Torvalds 2026-02-21 54 struct syscon *syscon __free(kfree) = kzalloc_obj(*syscon); bdb0066df96e74 Pankaj Dubey 2014-09-30 55 if (!syscon) bdb0066df96e74 Pankaj Dubey 2014-09-30 56 return ERR_PTR(-ENOMEM); bdb0066df96e74 Pankaj Dubey 2014-09-30 57 82f898f47112bc Krzysztof Kozlowski 2024-07-07 58 if (of_address_to_resource(np, 0, &res)) 82f898f47112bc Krzysztof Kozlowski 2024-07-07 59 return ERR_PTR(-ENOMEM); ca668f0edfae65 Philipp Zabel 2016-01-29 60 452d07413954ef Hector Martin 2021-08-23 61 base = of_iomap(np, 0); 82f898f47112bc Krzysztof Kozlowski 2024-07-07 62 if (!base) 82f898f47112bc Krzysztof Kozlowski 2024-07-07 63 return ERR_PTR(-ENOMEM); bdb0066df96e74 Pankaj Dubey 2014-09-30 64 ca4582c286aa44 Jason A. Donenfeld 2022-10-08 65 /* Parse the device's DT node for an endianness specification */ ca4582c286aa44 Jason A. Donenfeld 2022-10-08 66 if (of_property_read_bool(np, "big-endian")) ca4582c286aa44 Jason A. Donenfeld 2022-10-08 67 syscon_config.val_format_endian = REGMAP_ENDIAN_BIG; ca4582c286aa44 Jason A. Donenfeld 2022-10-08 68 else if (of_property_read_bool(np, "little-endian")) ca4582c286aa44 Jason A. Donenfeld 2022-10-08 69 syscon_config.val_format_endian = REGMAP_ENDIAN_LITTLE; ca4582c286aa44 Jason A. Donenfeld 2022-10-08 70 else if (of_property_read_bool(np, "native-endian")) ca4582c286aa44 Jason A. Donenfeld 2022-10-08 71 syscon_config.val_format_endian = REGMAP_ENDIAN_NATIVE; ca4582c286aa44 Jason A. Donenfeld 2022-10-08 72 db2fb60cd35d2d Damien Riegel 2015-11-30 73 /* db2fb60cd35d2d Damien Riegel 2015-11-30 74 * search for reg-io-width property in DT. If it is not provided, db2fb60cd35d2d Damien Riegel 2015-11-30 75 * default to 4 bytes. regmap_init_mmio will return an error if values db2fb60cd35d2d Damien Riegel 2015-11-30 76 * are invalid so there is no need to check them here. db2fb60cd35d2d Damien Riegel 2015-11-30 77 */ db2fb60cd35d2d Damien Riegel 2015-11-30 78 ret = of_property_read_u32(np, "reg-io-width", ®_io_width); db2fb60cd35d2d Damien Riegel 2015-11-30 79 if (ret) db2fb60cd35d2d Damien Riegel 2015-11-30 80 reg_io_width = 4; db2fb60cd35d2d Damien Riegel 2015-11-30 81 3bafc09e779710 Baolin Wang 2017-12-25 82 ret = of_hwspin_lock_get_id(np, 0); 3bafc09e779710 Baolin Wang 2017-12-25 83 if (ret > 0 || (IS_ENABLED(CONFIG_HWSPINLOCK) && ret == 0)) { 3bafc09e779710 Baolin Wang 2017-12-25 84 syscon_config.use_hwlock = true; 3bafc09e779710 Baolin Wang 2017-12-25 85 syscon_config.hwlock_id = ret; 3bafc09e779710 Baolin Wang 2017-12-25 86 syscon_config.hwlock_mode = HWLOCK_IRQSTATE; 3bafc09e779710 Baolin Wang 2017-12-25 87 } else if (ret < 0) { 3bafc09e779710 Baolin Wang 2017-12-25 88 switch (ret) { 3bafc09e779710 Baolin Wang 2017-12-25 89 case -ENOENT: 3bafc09e779710 Baolin Wang 2017-12-25 90 /* Ignore missing hwlock, it's optional. */ 3bafc09e779710 Baolin Wang 2017-12-25 91 break; 3bafc09e779710 Baolin Wang 2017-12-25 92 default: 3bafc09e779710 Baolin Wang 2017-12-25 93 pr_err("Failed to retrieve valid hwlock: %d\n", ret); df561f6688fef7 Gustavo A. R. Silva 2020-08-23 94 fallthrough; 3bafc09e779710 Baolin Wang 2017-12-25 95 case -EPROBE_DEFER: 3bafc09e779710 Baolin Wang 2017-12-25 96 goto err_regmap; 3bafc09e779710 Baolin Wang 2017-12-25 97 } 3bafc09e779710 Baolin Wang 2017-12-25 98 } 3bafc09e779710 Baolin Wang 2017-12-25 99 ba09916efb29f8 Eder Zulian 2025-02-12 100 res_size = resource_size(&res); ba09916efb29f8 Eder Zulian 2025-02-12 101 if (res_size < reg_io_width) { ba09916efb29f8 Eder Zulian 2025-02-12 102 ret = -EFAULT; ba09916efb29f8 Eder Zulian 2025-02-12 103 goto err_regmap; ba09916efb29f8 Eder Zulian 2025-02-12 104 } ba09916efb29f8 Eder Zulian 2025-02-12 105 7ff7d5ffb7259f Andy Shevchenko 2022-05-31 106 syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%pa", np, &res.start); 41673c66b3d0c0 Kunwu Chan 2023-12-04 107 if (!syscon_config.name) { 41673c66b3d0c0 Kunwu Chan 2023-12-04 108 ret = -ENOMEM; 41673c66b3d0c0 Kunwu Chan 2023-12-04 109 goto err_regmap; 41673c66b3d0c0 Kunwu Chan 2023-12-04 110 } db2fb60cd35d2d Damien Riegel 2015-11-30 111 syscon_config.reg_stride = reg_io_width; db2fb60cd35d2d Damien Riegel 2015-11-30 112 syscon_config.val_bits = reg_io_width * 8; ba09916efb29f8 Eder Zulian 2025-02-12 113 syscon_config.max_register = res_size - reg_io_width; 2e63d6fa113d36 Nishanth Menon 2024-09-03 114 if (!syscon_config.max_register) 2e63d6fa113d36 Nishanth Menon 2024-09-03 115 syscon_config.max_register_is_0 = true; db2fb60cd35d2d Damien Riegel 2015-11-30 116 bdb0066df96e74 Pankaj Dubey 2014-09-30 117 regmap = regmap_init_mmio(NULL, base, &syscon_config); 56a1188159cb2b Limeng 2021-04-07 118 kfree(syscon_config.name); bdb0066df96e74 Pankaj Dubey 2014-09-30 119 if (IS_ERR(regmap)) { bdb0066df96e74 Pankaj Dubey 2014-09-30 120 pr_err("regmap init failed\n"); bdb0066df96e74 Pankaj Dubey 2014-09-30 121 ret = PTR_ERR(regmap); bdb0066df96e74 Pankaj Dubey 2014-09-30 122 goto err_regmap; bdb0066df96e74 Pankaj Dubey 2014-09-30 123 } bdb0066df96e74 Pankaj Dubey 2014-09-30 124 7d1e3bd94828ad Jeremy Kerr 2023-01-05 @125 if (check_res) { a00406b71c5f08 Fabrice Gasnier 2018-12-12 126 clk = of_clk_get(np, 0); a00406b71c5f08 Fabrice Gasnier 2018-12-12 127 if (IS_ERR(clk)) { a00406b71c5f08 Fabrice Gasnier 2018-12-12 128 ret = PTR_ERR(clk); a00406b71c5f08 Fabrice Gasnier 2018-12-12 129 /* clock is optional */ a00406b71c5f08 Fabrice Gasnier 2018-12-12 130 if (ret != -ENOENT) a00406b71c5f08 Fabrice Gasnier 2018-12-12 131 goto err_clk; a00406b71c5f08 Fabrice Gasnier 2018-12-12 132 } else { a00406b71c5f08 Fabrice Gasnier 2018-12-12 133 ret = regmap_mmio_attach_clk(regmap, clk); a00406b71c5f08 Fabrice Gasnier 2018-12-12 134 if (ret) 7d1e3bd94828ad Jeremy Kerr 2023-01-05 135 goto err_attach_clk; a00406b71c5f08 Fabrice Gasnier 2018-12-12 136 } 7d1e3bd94828ad Jeremy Kerr 2023-01-05 137 7d1e3bd94828ad Jeremy Kerr 2023-01-05 138 reset = of_reset_control_get_optional_exclusive(np, NULL); 7d1e3bd94828ad Jeremy Kerr 2023-01-05 139 if (IS_ERR(reset)) { 7d1e3bd94828ad Jeremy Kerr 2023-01-05 140 ret = PTR_ERR(reset); 7d1e3bd94828ad Jeremy Kerr 2023-01-05 141 goto err_attach_clk; 7d1e3bd94828ad Jeremy Kerr 2023-01-05 142 } 7d1e3bd94828ad Jeremy Kerr 2023-01-05 143 7d1e3bd94828ad Jeremy Kerr 2023-01-05 144 ret = reset_control_deassert(reset); 7d1e3bd94828ad Jeremy Kerr 2023-01-05 145 if (ret) 7d1e3bd94828ad Jeremy Kerr 2023-01-05 146 goto err_reset; 39233b7c611248 Paul Cercueil 2019-07-24 147 } a00406b71c5f08 Fabrice Gasnier 2018-12-12 148 bdb0066df96e74 Pankaj Dubey 2014-09-30 149 syscon->regmap = regmap; bdb0066df96e74 Pankaj Dubey 2014-09-30 150 syscon->np = np; daad85a71f976e WenTao Liang 2026-06-26 151 syscon->reset = reset; bdb0066df96e74 Pankaj Dubey 2014-09-30 152 bdb0066df96e74 Pankaj Dubey 2014-09-30 153 list_add_tail(&syscon->list, &syscon_list); 87d687301f3807 Dong Aisheng 2012-09-05 154 82f898f47112bc Krzysztof Kozlowski 2024-07-07 155 return_ptr(syscon); bdb0066df96e74 Pankaj Dubey 2014-09-30 156 7d1e3bd94828ad Jeremy Kerr 2023-01-05 157 err_reset: 7d1e3bd94828ad Jeremy Kerr 2023-01-05 158 reset_control_put(reset); 7d1e3bd94828ad Jeremy Kerr 2023-01-05 159 err_attach_clk: a00406b71c5f08 Fabrice Gasnier 2018-12-12 160 if (!IS_ERR(clk)) a00406b71c5f08 Fabrice Gasnier 2018-12-12 161 clk_put(clk); a00406b71c5f08 Fabrice Gasnier 2018-12-12 162 err_clk: a00406b71c5f08 Fabrice Gasnier 2018-12-12 163 regmap_exit(regmap); bdb0066df96e74 Pankaj Dubey 2014-09-30 164 err_regmap: bdb0066df96e74 Pankaj Dubey 2014-09-30 165 iounmap(base); bdb0066df96e74 Pankaj Dubey 2014-09-30 166 return ERR_PTR(ret); 87d687301f3807 Dong Aisheng 2012-09-05 167 } 87d687301f3807 Dong Aisheng 2012-09-05 168 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki