Skip to content

Commit 1332661

Browse files
Yuuoniykrzk
authored andcommitted
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: 6e7674c ("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>
1 parent 038ae37 commit 1332661

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

drivers/memory/samsung/exynos5422-dmc.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,33 +1187,39 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
11871187

11881188
dmc->timing_row = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
11891189
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+
}
11921194

11931195
dmc->timing_data = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
11941196
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+
}
11971201

11981202
dmc->timing_power = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
11991203
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+
}
12021208

12031209
dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dmc->dev,
12041210
DDR_TYPE_LPDDR3,
12051211
&dmc->timings_arr_size);
12061212
if (!dmc->timings) {
1207-
of_node_put(np_ddr);
12081213
dev_warn(dmc->dev, "could not get timings from DT\n");
1209-
return -EINVAL;
1214+
ret = -EINVAL;
1215+
goto put_node;
12101216
}
12111217

12121218
dmc->min_tck = of_lpddr3_get_min_tck(np_ddr, dmc->dev);
12131219
if (!dmc->min_tck) {
1214-
of_node_put(np_ddr);
12151220
dev_warn(dmc->dev, "could not get tck from DT\n");
1216-
return -EINVAL;
1221+
ret = -EINVAL;
1222+
goto put_node;
12171223
}
12181224

12191225
/* Sorted array of OPPs with frequency ascending */
@@ -1227,13 +1233,14 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
12271233
clk_period_ps);
12281234
}
12291235

1230-
of_node_put(np_ddr);
12311236

12321237
/* Take the highest frequency's timings as 'bypass' */
12331238
dmc->bypass_timing_row = dmc->timing_row[idx - 1];
12341239
dmc->bypass_timing_data = dmc->timing_data[idx - 1];
12351240
dmc->bypass_timing_power = dmc->timing_power[idx - 1];
12361241

1242+
put_node:
1243+
of_node_put(np_ddr);
12371244
return ret;
12381245
}
12391246

0 commit comments

Comments
 (0)