memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings

of_parse_phandle() returns a node pointer with refcount
incremented, we should use of_node_put() on it when not need anymore.
This function doesn't call of_node_put() in some error paths.
To unify the structure, Add put_node label and goto it on errors.

Fixes: 6e7674c3c6df ("memory: Add DMC driver for Exynos5422")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://lore.kernel.org/r/20220602041721.64348-1-linmq006@gmail.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

authored by Miaoqian Lin and committed by Krzysztof Kozlowski 1332661e 038ae37c

Changed files
+18 -11
drivers
memory
+18 -11
drivers/memory/samsung/exynos5422-dmc.c
··· 1187 1187 1188 1188 dmc->timing_row = devm_kmalloc_array(dmc->dev, TIMING_COUNT, 1189 1189 sizeof(u32), GFP_KERNEL); 1190 - if (!dmc->timing_row) 1191 - return -ENOMEM; 1190 + if (!dmc->timing_row) { 1191 + ret = -ENOMEM; 1192 + goto put_node; 1193 + } 1192 1194 1193 1195 dmc->timing_data = devm_kmalloc_array(dmc->dev, TIMING_COUNT, 1194 1196 sizeof(u32), GFP_KERNEL); 1195 - if (!dmc->timing_data) 1196 - return -ENOMEM; 1197 + if (!dmc->timing_data) { 1198 + ret = -ENOMEM; 1199 + goto put_node; 1200 + } 1197 1201 1198 1202 dmc->timing_power = devm_kmalloc_array(dmc->dev, TIMING_COUNT, 1199 1203 sizeof(u32), GFP_KERNEL); 1200 - if (!dmc->timing_power) 1201 - return -ENOMEM; 1204 + if (!dmc->timing_power) { 1205 + ret = -ENOMEM; 1206 + goto put_node; 1207 + } 1202 1208 1203 1209 dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dmc->dev, 1204 1210 DDR_TYPE_LPDDR3, 1205 1211 &dmc->timings_arr_size); 1206 1212 if (!dmc->timings) { 1207 - of_node_put(np_ddr); 1208 1213 dev_warn(dmc->dev, "could not get timings from DT\n"); 1209 - return -EINVAL; 1214 + ret = -EINVAL; 1215 + goto put_node; 1210 1216 } 1211 1217 1212 1218 dmc->min_tck = of_lpddr3_get_min_tck(np_ddr, dmc->dev); 1213 1219 if (!dmc->min_tck) { 1214 - of_node_put(np_ddr); 1215 1220 dev_warn(dmc->dev, "could not get tck from DT\n"); 1216 - return -EINVAL; 1221 + ret = -EINVAL; 1222 + goto put_node; 1217 1223 } 1218 1224 1219 1225 /* Sorted array of OPPs with frequency ascending */ ··· 1233 1227 clk_period_ps); 1234 1228 } 1235 1229 1236 - of_node_put(np_ddr); 1237 1230 1238 1231 /* Take the highest frequency's timings as 'bypass' */ 1239 1232 dmc->bypass_timing_row = dmc->timing_row[idx - 1]; 1240 1233 dmc->bypass_timing_data = dmc->timing_data[idx - 1]; 1241 1234 dmc->bypass_timing_power = dmc->timing_power[idx - 1]; 1242 1235 1236 + put_node: 1237 + of_node_put(np_ddr); 1243 1238 return ret; 1244 1239 } 1245 1240