Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

soundwire: fix usages of device_get_named_child_node()

The documentation for device_get_named_child_node() mentions this
important point:

"
The caller is responsible for calling fwnode_handle_put() on the
returned fwnode pointer.
"

Add fwnode_handle_put() to avoid leaked references.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20240429004935.2400191-1-yung-chuan.liao@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Pierre-Louis Bossart and committed by
Vinod Koul
e2d8ea0a 1613e604

+32 -7
+3
drivers/soundwire/amd_manager.c
··· 571 571 amd_manager->wake_en_mask = wake_en_mask; 572 572 fwnode_property_read_u32(link, "amd-sdw-power-mode", &power_mode_mask); 573 573 amd_manager->power_mode_mask = power_mode_mask; 574 + 575 + fwnode_handle_put(link); 576 + 574 577 return 0; 575 578 } 576 579
+5 -1
drivers/soundwire/intel_auxdevice.c
··· 155 155 SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY; 156 156 157 157 intel_prop = devm_kzalloc(bus->dev, sizeof(*intel_prop), GFP_KERNEL); 158 - if (!intel_prop) 158 + if (!intel_prop) { 159 + fwnode_handle_put(link); 159 160 return -ENOMEM; 161 + } 160 162 161 163 /* initialize with hardware defaults, in case the properties are not found */ 162 164 intel_prop->doaise = 0x1; ··· 185 183 intel_prop->doais, 186 184 intel_prop->dodse, 187 185 intel_prop->dods); 186 + 187 + fwnode_handle_put(link); 188 188 189 189 return 0; 190 190 }
+24 -6
drivers/soundwire/mipi_disco.c
··· 66 66 prop->clk_freq = devm_kcalloc(bus->dev, prop->num_clk_freq, 67 67 sizeof(*prop->clk_freq), 68 68 GFP_KERNEL); 69 - if (!prop->clk_freq) 69 + if (!prop->clk_freq) { 70 + fwnode_handle_put(link); 70 71 return -ENOMEM; 72 + } 71 73 72 74 fwnode_property_read_u32_array(link, 73 75 "mipi-sdw-clock-frequencies-supported", ··· 94 92 prop->clk_gears = devm_kcalloc(bus->dev, prop->num_clk_gears, 95 93 sizeof(*prop->clk_gears), 96 94 GFP_KERNEL); 97 - if (!prop->clk_gears) 95 + if (!prop->clk_gears) { 96 + fwnode_handle_put(link); 98 97 return -ENOMEM; 98 + } 99 99 100 100 fwnode_property_read_u32_array(link, 101 101 "mipi-sdw-supported-clock-gears", ··· 119 115 120 116 fwnode_property_read_u32(link, "mipi-sdw-command-error-threshold", 121 117 &prop->err_threshold); 118 + 119 + fwnode_handle_put(link); 122 120 123 121 return 0; 124 122 } ··· 203 197 dpn[i].num_words, 204 198 sizeof(*dpn[i].words), 205 199 GFP_KERNEL); 206 - if (!dpn[i].words) 200 + if (!dpn[i].words) { 201 + fwnode_handle_put(node); 207 202 return -ENOMEM; 203 + } 208 204 209 205 fwnode_property_read_u32_array(node, 210 206 "mipi-sdw-port-wordlength-configs", ··· 244 236 dpn[i].num_channels, 245 237 sizeof(*dpn[i].channels), 246 238 GFP_KERNEL); 247 - if (!dpn[i].channels) 239 + if (!dpn[i].channels) { 240 + fwnode_handle_put(node); 248 241 return -ENOMEM; 242 + } 249 243 250 244 fwnode_property_read_u32_array(node, 251 245 "mipi-sdw-channel-number-list", ··· 261 251 dpn[i].num_ch_combinations, 262 252 sizeof(*dpn[i].ch_combinations), 263 253 GFP_KERNEL); 264 - if (!dpn[i].ch_combinations) 254 + if (!dpn[i].ch_combinations) { 255 + fwnode_handle_put(node); 265 256 return -ENOMEM; 257 + } 266 258 267 259 fwnode_property_read_u32_array(node, 268 260 "mipi-sdw-channel-combination-list", ··· 285 273 &dpn[i].port_encoding); 286 274 287 275 /* TODO: Read audio mode */ 276 + 277 + fwnode_handle_put(node); 288 278 289 279 i++; 290 280 } ··· 362 348 prop->dp0_prop = devm_kzalloc(&slave->dev, 363 349 sizeof(*prop->dp0_prop), 364 350 GFP_KERNEL); 365 - if (!prop->dp0_prop) 351 + if (!prop->dp0_prop) { 352 + fwnode_handle_put(port); 366 353 return -ENOMEM; 354 + } 367 355 368 356 sdw_slave_read_dp0(slave, port, prop->dp0_prop); 357 + 358 + fwnode_handle_put(port); 369 359 } 370 360 371 361 /*